Ignore:
File:
1 edited

Legend:

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

    r95d45482 raab5e46  
    4848#include <synch/spinlock.h>
    4949#include <synch/waitq.h>
     50#include <synch/workqueue.h>
     51#include <synch/rcu.h>
    5052#include <cpu.h>
    5153#include <str.h>
     
    6769#include <syscall/copy.h>
    6870#include <errno.h>
    69 #include <debug.h>
    7071
    7172/** Thread states */
     
    165166
    166167#ifdef CONFIG_FPU
    167         thread->saved_fpu_context = slab_alloc(fpu_context_cache,
    168             FRAME_ATOMIC | kmflags);
     168#ifdef CONFIG_FPU_LAZY
     169        thread->saved_fpu_context = NULL;
     170#else /* CONFIG_FPU_LAZY */
     171        thread->saved_fpu_context = slab_alloc(fpu_context_cache, kmflags);
    169172        if (!thread->saved_fpu_context)
    170173                return ENOMEM;
     174#endif /* CONFIG_FPU_LAZY */
    171175#endif /* CONFIG_FPU */
    172176
     
    190194        kmflags &= ~FRAME_HIGHMEM;
    191195
    192         // NOTE: All kernel stacks must be aligned to STACK_SIZE,
    193         //       see get_stack_base().
     196        // XXX: All kernel stacks must be aligned to STACK_SIZE,
     197        //      see get_stack_base().
    194198
    195199        uintptr_t stack_phys =
     
    197201        if (!stack_phys) {
    198202#ifdef CONFIG_FPU
    199                 assert(thread->saved_fpu_context);
    200                 slab_free(fpu_context_cache, thread->saved_fpu_context);
     203                if (thread->saved_fpu_context)
     204                        slab_free(fpu_context_cache, thread->saved_fpu_context);
    201205#endif
    202206                return ENOMEM;
     
    223227
    224228#ifdef CONFIG_FPU
    225         assert(thread->saved_fpu_context);
    226         slab_free(fpu_context_cache, thread->saved_fpu_context);
     229        if (thread->saved_fpu_context)
     230                slab_free(fpu_context_cache, thread->saved_fpu_context);
    227231#endif
    228232
     
    268272{
    269273        assert(irq_spinlock_locked(&thread->lock));
     274        workq_before_thread_is_ready(thread);
    270275}
    271276
     
    339344    thread_flags_t flags, const char *name)
    340345{
    341         thread_t *thread = (thread_t *) slab_alloc(thread_cache, FRAME_ATOMIC);
     346        thread_t *thread = (thread_t *) slab_alloc(thread_cache, 0);
    342347        if (!thread)
    343348                return NULL;
    344 
    345         if (thread_create_arch(thread, flags) != EOK) {
    346                 slab_free(thread_cache, thread);
    347                 return NULL;
    348         }
    349349
    350350        /* Not needed, but good for debugging */
     
    399399        thread->task = task;
    400400
     401        thread->workq = NULL;
     402
    401403        thread->fpu_context_exists = false;
    402404        thread->fpu_context_engaged = false;
     
    409411        udebug_thread_initialize(&thread->udebug);
    410412#endif
     413
     414        /* Might depend on previous initialization */
     415        thread_create_arch(thread);
     416
     417        rcu_thread_init(thread);
    411418
    412419        if ((flags & THREAD_FLAG_NOATTACH) != THREAD_FLAG_NOATTACH)
     
    653660
    654661        return waitq_sleep_timeout(&thread->join_wq, usec, flags, NULL);
    655 
    656         // FIXME: join should deallocate the thread.
    657         //        Current code calls detach after join, that's contrary to how
    658         //        join is used in other threading APIs.
    659662}
    660663
Note: See TracChangeset for help on using the changeset viewer.