Changeset 6eef3c4 in mainline for kernel/generic/src/proc/thread.c


Ignore:
Timestamp:
2012-06-20T16:18:37Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8b36bf2, f22dc820
Parents:
abfc9f3
Message:

cleanup thread_create() and thread_t structure

  • remove 'flag' bitfield from thread_t, use individual boolean flags (can be optimized later on by adding : 1)
  • use an enum for call flags, add THREAD_FLAG_NONE
  • remove the 'uncounted' argument in favour of a call flag
  • introduce thread_wire() to setup wired threads
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/proc/thread.c

    rabfc9f3 r6eef3c4  
    191191        kmflags |= FRAME_LOWMEM;
    192192        kmflags &= ~FRAME_HIGHMEM;
    193 
     193       
    194194        thread->kstack = (uint8_t *) frame_alloc(STACK_FRAMES, FRAME_KA | kmflags);
    195195        if (!thread->kstack) {
     
    247247}
    248248
     249/** Wire thread to the given CPU
     250 *
     251 * @param cpu CPU to wire the thread to.
     252 *
     253 */
     254void thread_wire(thread_t *thread, cpu_t *cpu)
     255{
     256        irq_spinlock_lock(&thread->lock, true);
     257        thread->cpu = cpu;
     258        thread->wired = true;
     259        irq_spinlock_unlock(&thread->lock, true);
     260}
     261
    249262/** Make thread ready
    250263 *
     
    260273        ASSERT(thread->state != Ready);
    261274       
    262         int i = (thread->priority < RQ_COUNT - 1)
    263             ? ++thread->priority : thread->priority;
    264        
    265         cpu_t *cpu = CPU;
    266         if (thread->flags & THREAD_FLAG_WIRED) {
     275        int i = (thread->priority < RQ_COUNT - 1) ?
     276            ++thread->priority : thread->priority;
     277       
     278        cpu_t *cpu;
     279        if (thread->wired) {
    267280                ASSERT(thread->cpu != NULL);
    268281                cpu = thread->cpu;
    269         }
     282        } else
     283                cpu = CPU;
     284       
    270285        thread->state = Ready;
    271286       
     
    298313 * @param flags     Thread flags.
    299314 * @param name      Symbolic name (a copy is made).
    300  * @param uncounted Thread's accounting doesn't affect accumulated task
    301  *                  accounting.
    302315 *
    303316 * @return New thread's structure on success, NULL on failure.
     
    305318 */
    306319thread_t *thread_create(void (* func)(void *), void *arg, task_t *task,
    307     unsigned int flags, const char *name, bool uncounted)
     320    thread_flags_t flags, const char *name)
    308321{
    309322        thread_t *thread = (thread_t *) slab_alloc(thread_slab, 0);
     
    335348        thread->ucycles = 0;
    336349        thread->kcycles = 0;
    337         thread->uncounted = uncounted;
     350        thread->uncounted =
     351            ((flags & THREAD_FLAG_UNCOUNTED) == THREAD_FLAG_UNCOUNTED);
    338352        thread->priority = -1;          /* Start in rq[0] */
    339353        thread->cpu = NULL;
    340         thread->flags = flags;
     354        thread->wired = false;
     355        thread->stolen = false;
     356        thread->uspace =
     357            ((flags & THREAD_FLAG_USPACE) == THREAD_FLAG_USPACE);
     358       
    341359        thread->nomigrate = 0;
    342360        thread->state = Entering;
     
    356374        thread->task = task;
    357375       
    358         thread->fpu_context_exists = 0;
    359         thread->fpu_context_engaged = 0;
     376        thread->fpu_context_exists = false;
     377        thread->fpu_context_engaged = false;
    360378       
    361379        avltree_node_initialize(&thread->threads_tree_node);
     
    371389        thread_create_arch(thread);
    372390       
    373         if (!(flags & THREAD_FLAG_NOATTACH))
     391        if ((flags & THREAD_FLAG_NOATTACH) != THREAD_FLAG_NOATTACH)
    374392                thread_attach(thread, task);
    375393       
     
    437455       
    438456        /* Must not count kbox thread into lifecount */
    439         if (thread->flags & THREAD_FLAG_USPACE)
     457        if (thread->uspace)
    440458                atomic_inc(&task->lifecount);
    441459       
     
    459477void thread_exit(void)
    460478{
    461         if (THREAD->flags & THREAD_FLAG_USPACE) {
     479        if (THREAD->uspace) {
    462480#ifdef CONFIG_UDEBUG
    463481                /* Generate udebug THREAD_E event */
    464482                udebug_thread_e_event();
    465 
     483               
    466484                /*
    467485                 * This thread will not execute any code or system calls from
     
    506524{
    507525        ASSERT(THREAD);
    508 
     526       
    509527        THREAD->nomigrate++;
    510528}
     
    515533        ASSERT(THREAD);
    516534        ASSERT(THREAD->nomigrate > 0);
    517 
    518         THREAD->nomigrate--;
     535       
     536        if (THREAD->nomigrate > 0)
     537                THREAD->nomigrate--;
    519538}
    520539
     
    865884       
    866885        thread_t *thread = thread_create(uinit, kernel_uarg, TASK,
    867             THREAD_FLAG_USPACE | THREAD_FLAG_NOATTACH, namebuf, false);
     886            THREAD_FLAG_USPACE | THREAD_FLAG_NOATTACH, namebuf);
    868887        if (thread) {
    869888                if (uspace_thread_id != NULL) {
Note: See TracChangeset for help on using the changeset viewer.