Changeset 0f4f1b2 in mainline for kernel/generic/src


Ignore:
Timestamp:
2024-01-15T17:10:27Z (18 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
e82879c
Parents:
a064d4f
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-15 16:37:22)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-15 17:10:27)
Message:

Add (and use) functions thread_start() and thread_detach()

Mostly cosmetic, with thread_start() replacing calls to thread_ready(),
but not consuming the passed reference, and thread_detach() being
synonym for thread_put(). Makes the code's function more obvious.

Also modify some threaded tests to use thread_join() for waiting,
instead of counting threads with atomics or semaphores.

Location:
kernel/generic/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/cmd.c

    ra064d4f r0f4f1b2  
    10041004                        printf("cpu%u: ", i);
    10051005                        thread_wire(thread, &cpus[i]);
    1006                         thread_ready(thread_ref(thread));
     1006                        thread_start(thread);
    10071007                        thread_join(thread);
    10081008                } else
  • kernel/generic/src/ipc/kbox.c

    ra064d4f r0f4f1b2  
    246246                }
    247247
    248                 task->kb.thread = thread_ref(kb_thread);
    249                 thread_ready(kb_thread);
     248                task->kb.thread = kb_thread;
     249                thread_start(kb_thread);
    250250        }
    251251
  • kernel/generic/src/main/kinit.c

    ra064d4f r0f4f1b2  
    122122
    123123                thread_wire(thread, &cpus[0]);
    124                 thread_ready(thread_ref(thread));
     124                thread_start(thread);
    125125                thread_join(thread);
    126126
     
    135135                        if (thread != NULL) {
    136136                                thread_wire(thread, &cpus[i]);
    137                                 thread_ready(thread);
     137                                thread_start(thread);
     138                                thread_detach(thread);
    138139                        } else
    139140                                log(LF_OTHER, LVL_ERROR,
     
    151152        thread = thread_create(kload, NULL, TASK, THREAD_FLAG_NONE,
    152153            "kload");
    153         if (thread != NULL)
    154                 thread_ready(thread);
    155         else
     154        if (thread != NULL) {
     155                thread_start(thread);
     156                thread_detach(thread);
     157        } else {
    156158                log(LF_OTHER, LVL_ERROR, "Unable to create kload thread");
     159        }
    157160
    158161#ifdef CONFIG_KCONSOLE
     
    163166                thread = thread_create(kconsole_thread, NULL, TASK,
    164167                    THREAD_FLAG_NONE, "kconsole");
    165                 if (thread != NULL)
    166                         thread_ready(thread);
    167                 else
     168                if (thread != NULL) {
     169                        thread_start(thread);
     170                        thread_detach(thread);
     171                } else {
    168172                        log(LF_OTHER, LVL_ERROR,
    169173                            "Unable to create kconsole thread");
     174                }
    170175        }
    171176#endif /* CONFIG_KCONSOLE */
  • kernel/generic/src/main/main.c

    ra064d4f r0f4f1b2  
    282282        if (!kinit_thread)
    283283                panic("Cannot create kinit thread.");
    284         thread_ready(kinit_thread);
     284        thread_start(kinit_thread);
     285        thread_detach(kinit_thread);
    285286
    286287        /*
  • kernel/generic/src/proc/program.c

    ra064d4f r0f4f1b2  
    212212void program_ready(program_t *prg)
    213213{
    214         thread_ready(prg->main_thread);
     214        thread_start(prg->main_thread);
     215        thread_detach(prg->main_thread);
    215216        prg->main_thread = NULL;
    216217}
  • kernel/generic/src/proc/thread.c

    ra064d4f r0f4f1b2  
    234234}
    235235
     236/** Start a thread that wasn't started yet since it was created.
     237 *
     238 * @param thread A reference to the newly created thread.
     239 */
     240void thread_start(thread_t *thread)
     241{
     242        assert(thread->state == Entering);
     243        thread_ready(thread_ref(thread));
     244}
     245
    236246/** Make thread ready
    237247 *
     
    696706errno_t thread_join_timeout(thread_t *thread, uint32_t usec, unsigned int flags)
    697707{
     708        assert(thread != NULL);
     709
    698710        if (thread == THREAD)
    699711                return EINVAL;
     
    712724
    713725        return rc;
     726}
     727
     728void thread_detach(thread_t *thread)
     729{
     730        thread_put(thread);
    714731}
    715732
Note: See TracChangeset for help on using the changeset viewer.