Ignore:
File:
1 edited

Legend:

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

    raab5e46 r95d45482  
    4848#include <synch/spinlock.h>
    4949#include <synch/waitq.h>
    50 #include <synch/workqueue.h>
    51 #include <synch/rcu.h>
    5250#include <cpu.h>
    5351#include <str.h>
     
    6967#include <syscall/copy.h>
    7068#include <errno.h>
     69#include <debug.h>
    7170
    7271/** Thread states */
     
    166165
    167166#ifdef CONFIG_FPU
    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);
     167        thread->saved_fpu_context = slab_alloc(fpu_context_cache,
     168            FRAME_ATOMIC | kmflags);
    172169        if (!thread->saved_fpu_context)
    173170                return ENOMEM;
    174 #endif /* CONFIG_FPU_LAZY */
    175171#endif /* CONFIG_FPU */
    176172
     
    194190        kmflags &= ~FRAME_HIGHMEM;
    195191
    196         // XXX: All kernel stacks must be aligned to STACK_SIZE,
    197         //      see get_stack_base().
     192        // NOTE: All kernel stacks must be aligned to STACK_SIZE,
     193        //       see get_stack_base().
    198194
    199195        uintptr_t stack_phys =
     
    201197        if (!stack_phys) {
    202198#ifdef CONFIG_FPU
    203                 if (thread->saved_fpu_context)
    204                         slab_free(fpu_context_cache, thread->saved_fpu_context);
     199                assert(thread->saved_fpu_context);
     200                slab_free(fpu_context_cache, thread->saved_fpu_context);
    205201#endif
    206202                return ENOMEM;
     
    227223
    228224#ifdef CONFIG_FPU
    229         if (thread->saved_fpu_context)
    230                 slab_free(fpu_context_cache, thread->saved_fpu_context);
     225        assert(thread->saved_fpu_context);
     226        slab_free(fpu_context_cache, thread->saved_fpu_context);
    231227#endif
    232228
     
    272268{
    273269        assert(irq_spinlock_locked(&thread->lock));
    274         workq_before_thread_is_ready(thread);
    275270}
    276271
     
    344339    thread_flags_t flags, const char *name)
    345340{
    346         thread_t *thread = (thread_t *) slab_alloc(thread_cache, 0);
     341        thread_t *thread = (thread_t *) slab_alloc(thread_cache, FRAME_ATOMIC);
    347342        if (!thread)
    348343                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 
    403401        thread->fpu_context_exists = false;
    404402        thread->fpu_context_engaged = false;
     
    411409        udebug_thread_initialize(&thread->udebug);
    412410#endif
    413 
    414         /* Might depend on previous initialization */
    415         thread_create_arch(thread);
    416 
    417         rcu_thread_init(thread);
    418411
    419412        if ((flags & THREAD_FLAG_NOATTACH) != THREAD_FLAG_NOATTACH)
     
    660653
    661654        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.
    662659}
    663660
Note: See TracChangeset for help on using the changeset viewer.