Subversion Repositories HelenOS-historic

Rev

Rev 1571 | Rev 1581 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1571 Rev 1579
Line 231... Line 231...
231
 *
231
 *
232
 * Assume thread->lock is held!!
232
 * Assume thread->lock is held!!
233
 */
233
 */
234
void thread_destroy(thread_t *t)
234
void thread_destroy(thread_t *t)
235
{
235
{
-
 
236
    bool destroy_task = false; 
-
 
237
 
236
    ASSERT(t->state == Exiting);
238
    ASSERT(t->state == Exiting);
237
    ASSERT(t->task);
239
    ASSERT(t->task);
238
    ASSERT(t->cpu);
240
    ASSERT(t->cpu);
239
 
241
 
240
    spinlock_lock(&t->cpu->lock);
242
    spinlock_lock(&t->cpu->lock);
241
    if(t->cpu->fpu_owner==t)
243
    if(t->cpu->fpu_owner==t)
242
        t->cpu->fpu_owner=NULL;
244
        t->cpu->fpu_owner=NULL;
243
    spinlock_unlock(&t->cpu->lock);
245
    spinlock_unlock(&t->cpu->lock);
244
 
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);
-
 
252
 
245
    /*
253
    /*
246
     * Detach from the containing task.
254
     * Detach from the containing task.
247
     */
255
     */
248
    spinlock_lock(&t->task->lock);
256
    spinlock_lock(&t->task->lock);
249
    list_remove(&t->th_link);
257
    list_remove(&t->th_link);
-
 
258
    if (--t->task->refcount == 0) {
-
 
259
        t->task->accept_new_threads = false;
-
 
260
        destroy_task = true;
-
 
261
    }
250
    spinlock_unlock(&t->task->lock);
262
    spinlock_unlock(&t->task->lock);   
251
   
263
   
252
    spinlock_unlock(&t->lock);
264
    if (destroy_task)
253
   
-
 
254
    spinlock_lock(&threads_lock);
265
        task_destroy(t->task);
255
    btree_remove(&threads_btree, (btree_key_t) ((__address ) t), NULL);
-
 
256
    spinlock_unlock(&threads_lock);
-
 
257
   
266
   
258
    slab_free(thread_slab, t);
267
    slab_free(thread_slab, t);
259
}
268
}
260
 
269
 
261
/** Create new thread
270
/** Create new thread
Line 317... Line 326...
317
    t->sleep_queue = NULL;
326
    t->sleep_queue = NULL;
318
    t->timeout_pending = 0;
327
    t->timeout_pending = 0;
319
 
328
 
320
    t->in_copy_from_uspace = false;
329
    t->in_copy_from_uspace = false;
321
    t->in_copy_to_uspace = false;
330
    t->in_copy_to_uspace = false;
322
   
331
 
-
 
332
    t->interrupted = false;
323
    t->detached = false;
333
    t->detached = false;
324
    waitq_initialize(&t->join_wq);
334
    waitq_initialize(&t->join_wq);
325
   
335
   
326
    t->rwlock_holder_type = RWLOCK_NONE;
336
    t->rwlock_holder_type = RWLOCK_NONE;
327
       
337
       
Line 329... Line 339...
329
   
339
   
330
    t->fpu_context_exists = 0;
340
    t->fpu_context_exists = 0;
331
    t->fpu_context_engaged = 0;
341
    t->fpu_context_engaged = 0;
332
   
342
   
333
    /*
343
    /*
-
 
344
     * Attach to the containing task.
-
 
345
     */
-
 
346
    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
    }
-
 
352
    list_append(&t->th_link, &task->th_head);
-
 
353
    task->refcount++;
-
 
354
    spinlock_unlock(&task->lock);
-
 
355
 
-
 
356
    /*
334
     * Register this thread in the system-wide list.
357
     * Register this thread in the system-wide list.
335
     */
358
     */
336
    ipl = interrupts_disable();
359
    ipl = interrupts_disable();
337
    spinlock_lock(&threads_lock);
360
    spinlock_lock(&threads_lock);
338
    btree_insert(&threads_btree, (btree_key_t) ((__address) t), (void *) t, NULL);
361
    btree_insert(&threads_btree, (btree_key_t) ((__address) t), (void *) t, NULL);
339
    spinlock_unlock(&threads_lock);
362
    spinlock_unlock(&threads_lock);
340
   
363
   
341
    /*
-
 
342
     * Attach to the containing task.
-
 
343
     */
-
 
344
    spinlock_lock(&task->lock);
-
 
345
    list_append(&t->th_link, &task->th_head);
-
 
346
    spinlock_unlock(&task->lock);
-
 
347
   
-
 
348
    interrupts_restore(ipl);
364
    interrupts_restore(ipl);
349
   
365
   
350
    return t;
366
    return t;
351
}
367
}
352
 
368