Changeset 7509ddc in mainline for generic/src/proc/thread.c


Ignore:
Timestamp:
2006-06-04T21:54:49Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
34dcd3f
Parents:
2cb5e64
Message:

Framework for task_kill().
Some pieces (e.g. implementation of ktask_cleanup() kernel thread and
task_destroy() function) are missing.
Changed locking order for task lock, threads_lock and thread lock from
threads_lock, thread lock, task lock to task lock, threads_lock, thread lock.

File:
1 edited

Legend:

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

    r2cb5e64 r7509ddc  
    234234void thread_destroy(thread_t *t)
    235235{
     236        bool destroy_task = false;     
     237
    236238        ASSERT(t->state == Exiting);
    237239        ASSERT(t->task);
     
    242244                t->cpu->fpu_owner=NULL;
    243245        spinlock_unlock(&t->cpu->lock);
     246
     247        spinlock_unlock(&t->lock);
     248
     249        spinlock_lock(&threads_lock);
     250        btree_remove(&threads_btree, (btree_key_t) ((__address ) t), NULL);
     251        spinlock_unlock(&threads_lock);
    244252
    245253        /*
     
    248256        spinlock_lock(&t->task->lock);
    249257        list_remove(&t->th_link);
    250         spinlock_unlock(&t->task->lock);
    251        
    252         spinlock_unlock(&t->lock);
    253        
    254         spinlock_lock(&threads_lock);
    255         btree_remove(&threads_btree, (btree_key_t) ((__address ) t), NULL);
    256         spinlock_unlock(&threads_lock);
     258        if (--t->task->refcount == 0) {
     259                t->task->accept_new_threads = false;
     260                destroy_task = true;
     261        }
     262        spinlock_unlock(&t->task->lock);       
     263       
     264        if (destroy_task)
     265                task_destroy(t->task);
    257266       
    258267        slab_free(thread_slab, t);
     
    320329        t->in_copy_from_uspace = false;
    321330        t->in_copy_to_uspace = false;
    322        
     331
     332        t->interrupted = false;
    323333        t->detached = false;
    324334        waitq_initialize(&t->join_wq);
     
    330340        t->fpu_context_exists = 0;
    331341        t->fpu_context_engaged = 0;
    332        
    333         /*
    334          * Register this thread in the system-wide list.
    335          */
    336         ipl = interrupts_disable();
    337         spinlock_lock(&threads_lock);
    338         btree_insert(&threads_btree, (btree_key_t) ((__address) t), (void *) t, NULL);
    339         spinlock_unlock(&threads_lock);
    340342       
    341343        /*
     
    343345         */
    344346        spinlock_lock(&task->lock);
     347        if (!task->accept_new_threads) {
     348                spinlock_unlock(&task->lock);
     349                slab_free(thread_slab, t);
     350                return NULL;
     351        }
    345352        list_append(&t->th_link, &task->th_head);
     353        task->refcount++;
    346354        spinlock_unlock(&task->lock);
     355
     356        /*
     357         * Register this thread in the system-wide list.
     358         */
     359        ipl = interrupts_disable();
     360        spinlock_lock(&threads_lock);
     361        btree_insert(&threads_btree, (btree_key_t) ((__address) t), (void *) t, NULL);
     362        spinlock_unlock(&threads_lock);
    347363       
    348364        interrupts_restore(ipl);
Note: See TracChangeset for help on using the changeset viewer.