Ignore:
File:
1 edited

Legend:

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

    rf22dc820 r38ff925  
    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) {
     
    236236       
    237237        atomic_set(&nrdy, 0);
    238         thread_slab = slab_cache_create("thread_t", sizeof(thread_t), 0,
     238        thread_slab = slab_cache_create("thread_slab", sizeof(thread_t), 0,
    239239            thr_constructor, thr_destructor, 0);
    240240       
    241241#ifdef CONFIG_FPU
    242         fpu_context_slab = slab_cache_create("fpu_context_t",
    243             sizeof(fpu_context_t), FPU_CONTEXT_ALIGN, NULL, NULL, 0);
     242        fpu_context_slab = slab_cache_create("fpu_slab", sizeof(fpu_context_t),
     243            FPU_CONTEXT_ALIGN, NULL, NULL, 0);
    244244#endif
    245245       
     
    247247}
    248248
    249 /** Wire thread to the given CPU
    250  *
    251  * @param cpu CPU to wire the thread to.
    252  *
    253  */
    254 void thread_wire(thread_t *thread, cpu_t *cpu)
     249/** Make thread ready
     250 *
     251 * Switch thread to the ready state.
     252 *
     253 * @param thread Thread to make ready.
     254 *
     255 */
     256void thread_ready(thread_t *thread)
    255257{
    256258        irq_spinlock_lock(&thread->lock, true);
    257         thread->cpu = cpu;
    258         thread->wired = true;
    259         irq_spinlock_unlock(&thread->lock, true);
    260 }
    261 
    262 /** Make thread ready
    263  *
    264  * Switch thread to the ready state.
    265  *
    266  * @param thread Thread to make ready.
    267  *
    268  */
    269 void thread_ready(thread_t *thread)
    270 {
    271         irq_spinlock_lock(&thread->lock, true);
    272259       
    273260        ASSERT(thread->state != Ready);
    274261       
    275         int i = (thread->priority < RQ_COUNT - 1) ?
    276             ++thread->priority : thread->priority;
    277        
    278         cpu_t *cpu;
    279         if (thread->wired || thread->nomigrate || thread->fpu_context_engaged) {
     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) {
    280267                ASSERT(thread->cpu != NULL);
    281268                cpu = thread->cpu;
    282         } else
    283                 cpu = CPU;
    284        
     269        }
    285270        thread->state = Ready;
    286271       
     
    313298 * @param flags     Thread flags.
    314299 * @param name      Symbolic name (a copy is made).
     300 * @param uncounted Thread's accounting doesn't affect accumulated task
     301 *                  accounting.
    315302 *
    316303 * @return New thread's structure on success, NULL on failure.
     
    318305 */
    319306thread_t *thread_create(void (* func)(void *), void *arg, task_t *task,
    320     thread_flags_t flags, const char *name)
     307    unsigned int flags, const char *name, bool uncounted)
    321308{
    322309        thread_t *thread = (thread_t *) slab_alloc(thread_slab, 0);
     
    348335        thread->ucycles = 0;
    349336        thread->kcycles = 0;
    350         thread->uncounted =
    351             ((flags & THREAD_FLAG_UNCOUNTED) == THREAD_FLAG_UNCOUNTED);
     337        thread->uncounted = uncounted;
    352338        thread->priority = -1;          /* Start in rq[0] */
    353339        thread->cpu = NULL;
    354         thread->wired = false;
    355         thread->stolen = false;
    356         thread->uspace =
    357             ((flags & THREAD_FLAG_USPACE) == THREAD_FLAG_USPACE);
    358        
     340        thread->flags = flags;
    359341        thread->nomigrate = 0;
    360342        thread->state = Entering;
     
    374356        thread->task = task;
    375357       
    376         thread->fpu_context_exists = false;
    377         thread->fpu_context_engaged = false;
     358        thread->fpu_context_exists = 0;
     359        thread->fpu_context_engaged = 0;
    378360       
    379361        avltree_node_initialize(&thread->threads_tree_node);
     
    389371        thread_create_arch(thread);
    390372       
    391         if ((flags & THREAD_FLAG_NOATTACH) != THREAD_FLAG_NOATTACH)
     373        if (!(flags & THREAD_FLAG_NOATTACH))
    392374                thread_attach(thread, task);
    393375       
     
    455437       
    456438        /* Must not count kbox thread into lifecount */
    457         if (thread->uspace)
     439        if (thread->flags & THREAD_FLAG_USPACE)
    458440                atomic_inc(&task->lifecount);
    459441       
     
    477459void thread_exit(void)
    478460{
    479         if (THREAD->uspace) {
     461        if (THREAD->flags & THREAD_FLAG_USPACE) {
    480462#ifdef CONFIG_UDEBUG
    481463                /* Generate udebug THREAD_E event */
    482464                udebug_thread_e_event();
    483                
     465
    484466                /*
    485467                 * This thread will not execute any code or system calls from
     
    524506{
    525507        ASSERT(THREAD);
    526        
     508
    527509        THREAD->nomigrate++;
    528510}
     
    533515        ASSERT(THREAD);
    534516        ASSERT(THREAD->nomigrate > 0);
    535        
    536         if (THREAD->nomigrate > 0)
    537                 THREAD->nomigrate--;
     517
     518        THREAD->nomigrate--;
    538519}
    539520
     
    873854         * In case of failure, kernel_uarg will be deallocated in this function.
    874855         * In case of success, kernel_uarg will be freed in uinit().
     856         *
    875857         */
    876858        uspace_arg_t *kernel_uarg =
     
    884866       
    885867        thread_t *thread = thread_create(uinit, kernel_uarg, TASK,
    886             THREAD_FLAG_USPACE | THREAD_FLAG_NOATTACH, namebuf);
     868            THREAD_FLAG_USPACE | THREAD_FLAG_NOATTACH, namebuf, false);
    887869        if (thread) {
    888870                if (uspace_thread_id != NULL) {
Note: See TracChangeset for help on using the changeset viewer.