Destroy thread memory structure * * Detach thread from all queues, cpus etc. and destroy it. * * @param thread Thread to be destroyed. * @param irq_res Indicate whether it should unlock thread->lock * in interrupts-restore mode. * */
| 428 | * |
| 429 | */ |
| 430 | void thread_destroy(thread_t *thread, bool irq_res) |
| 431 | { |
| 432 | assert(irq_spinlock_locked(&thread->lock)); |
| 433 | assert((thread->state == Exiting) || (thread->state == Lingering)); |
| 434 | assert(thread->task); |
| 435 | assert(thread->cpu); |
| 436 | |
| 437 | irq_spinlock_lock(&thread->cpu->lock, false); |
| 438 | if (thread->cpu->fpu_owner == thread) |
| 439 | thread->cpu->fpu_owner = NULL; |
| 440 | irq_spinlock_unlock(&thread->cpu->lock, false); |
| 441 | |
| 442 | irq_spinlock_pass(&thread->lock, &threads_lock); |
| 443 | |
| 444 | odict_remove(&thread->lthreads); |
| 445 | |
| 446 | irq_spinlock_pass(&threads_lock, &thread->task->lock); |
| 447 | |
| 448 | /* |
| 449 | * Detach from the containing task. |
| 450 | */ |
| 451 | list_remove(&thread->th_link); |
| 452 | irq_spinlock_unlock(&thread->task->lock, irq_res); |
| 453 | |
| 454 | /* |
| 455 | * Drop the reference to the containing task. |
| 456 | */ |
| 457 | task_release(thread->task); |
| 458 | slab_free(thread_cache, thread); |
| 459 | } |
| 460 | |
| 461 | /** Make the thread visible to the system. |
| 462 | * |
no test coverage detected