Rev 3222 | Rev 3565 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3222 | Rev 3438 | ||
---|---|---|---|
Line 178... | Line 178... | ||
178 | slab_free(fpu_context_slab, t->saved_fpu_context); |
178 | slab_free(fpu_context_slab, t->saved_fpu_context); |
179 | #endif |
179 | #endif |
180 | return -1; |
180 | return -1; |
181 | } |
181 | } |
182 | 182 | ||
- | 183 | #ifdef CONFIG_UDEBUG |
|
- | 184 | mutex_initialize(&t->udebug.lock, MUTEX_PASSIVE); |
|
- | 185 | #endif |
|
- | 186 | ||
183 | return 0; |
187 | return 0; |
184 | } |
188 | } |
185 | 189 | ||
186 | /** Destruction of thread_t object */ |
190 | /** Destruction of thread_t object */ |
187 | static int thr_destructor(void *obj) |
191 | static int thr_destructor(void *obj) |
Line 345... | Line 349... | ||
345 | t->fpu_context_engaged = 0; |
349 | t->fpu_context_engaged = 0; |
346 | 350 | ||
347 | avltree_node_initialize(&t->threads_tree_node); |
351 | avltree_node_initialize(&t->threads_tree_node); |
348 | t->threads_tree_node.key = (uintptr_t) t; |
352 | t->threads_tree_node.key = (uintptr_t) t; |
349 | 353 | ||
- | 354 | #ifdef CONFIG_UDEBUG |
|
- | 355 | /* Init debugging stuff */ |
|
- | 356 | udebug_thread_initialize(&t->udebug); |
|
- | 357 | #endif |
|
- | 358 | ||
350 | /* might depend on previous initialization */ |
359 | /* might depend on previous initialization */ |
351 | thread_create_arch(t); |
360 | thread_create_arch(t); |
352 | 361 | ||
353 | if (!(flags & THREAD_FLAG_NOATTACH)) |
362 | if (!(flags & THREAD_FLAG_NOATTACH)) |
354 | thread_attach(t, task); |
363 | thread_attach(t, task); |
Line 407... | Line 416... | ||
407 | void thread_attach(thread_t *t, task_t *task) |
416 | void thread_attach(thread_t *t, task_t *task) |
408 | { |
417 | { |
409 | ipl_t ipl; |
418 | ipl_t ipl; |
410 | 419 | ||
411 | /* |
420 | /* |
412 | * Attach to the current task. |
421 | * Attach to the specified task. |
413 | */ |
422 | */ |
414 | ipl = interrupts_disable(); |
423 | ipl = interrupts_disable(); |
415 | spinlock_lock(&task->lock); |
424 | spinlock_lock(&task->lock); |
- | 425 | ||
416 | atomic_inc(&task->refcount); |
426 | atomic_inc(&task->refcount); |
- | 427 | ||
- | 428 | /* Must not count kbox thread into lifecount */ |
|
- | 429 | if (t->flags & THREAD_FLAG_USPACE) |
|
417 | atomic_inc(&task->lifecount); |
430 | atomic_inc(&task->lifecount); |
- | 431 | ||
418 | list_append(&t->th_link, &task->th_head); |
432 | list_append(&t->th_link, &task->th_head); |
419 | spinlock_unlock(&task->lock); |
433 | spinlock_unlock(&task->lock); |
420 | 434 | ||
421 | /* |
435 | /* |
422 | * Register this thread in the system-wide list. |
436 | * Register this thread in the system-wide list. |
Line 435... | Line 449... | ||
435 | */ |
449 | */ |
436 | void thread_exit(void) |
450 | void thread_exit(void) |
437 | { |
451 | { |
438 | ipl_t ipl; |
452 | ipl_t ipl; |
439 | 453 | ||
- | 454 | if (THREAD->flags & THREAD_FLAG_USPACE) { |
|
- | 455 | #ifdef CONFIG_UDEBUG |
|
- | 456 | /* Generate udebug THREAD_E event */ |
|
- | 457 | udebug_thread_e_event(); |
|
- | 458 | #endif |
|
440 | if (atomic_predec(&TASK->lifecount) == 0) { |
459 | if (atomic_predec(&TASK->lifecount) == 0) { |
441 | /* |
460 | /* |
442 | * We are the last thread in the task that still has not exited. |
461 | * We are the last userspace thread in the task that |
- | 462 | * still has not exited. With the exception of the |
|
443 | * With the exception of the moment the task was created, new |
463 | * moment the task was created, new userspace threads |
444 | * threads can only be created by threads of the same task. |
464 | * can only be created by threads of the same task. |
445 | * We are safe to perform cleanup. |
465 | * We are safe to perform cleanup. |
446 | */ |
466 | */ |
447 | if (THREAD->flags & THREAD_FLAG_USPACE) { |
- | |
448 | ipc_cleanup(); |
467 | ipc_cleanup(); |
449 | futex_cleanup(); |
468 | futex_cleanup(); |
450 | LOG("Cleanup of task %" PRIu64" completed.", TASK->taskid); |
469 | LOG("Cleanup of task %" PRIu64" completed.", TASK->taskid); |
451 | } |
470 | } |
452 | } |
471 | } |
Line 739... | Line 758... | ||
739 | } |
758 | } |
740 | } |
759 | } |
741 | thread_attach(t, TASK); |
760 | thread_attach(t, TASK); |
742 | thread_ready(t); |
761 | thread_ready(t); |
743 | 762 | ||
- | 763 | #ifdef CONFIG_UDEBUG |
|
- | 764 | /* Generate udebug THREAD_B event */ |
|
- | 765 | udebug_thread_b_event(t); |
|
- | 766 | #endif |
|
- | 767 | ||
744 | return 0; |
768 | return 0; |
745 | } else |
769 | } else |
746 | free(kernel_uarg); |
770 | free(kernel_uarg); |
747 | 771 | ||
748 | return (unative_t) ENOMEM; |
772 | return (unative_t) ENOMEM; |