Rev 1380 | Rev 1576 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1380 | Rev 1571 | ||
---|---|---|---|
Line 38... | Line 38... | ||
38 | #include <proc/thread.h> |
38 | #include <proc/thread.h> |
39 | #include <proc/task.h> |
39 | #include <proc/task.h> |
40 | #include <mm/frame.h> |
40 | #include <mm/frame.h> |
41 | #include <mm/page.h> |
41 | #include <mm/page.h> |
42 | #include <mm/as.h> |
42 | #include <mm/as.h> |
- | 43 | #include <time/delay.h> |
|
43 | #include <arch/asm.h> |
44 | #include <arch/asm.h> |
44 | #include <arch/faddr.h> |
45 | #include <arch/faddr.h> |
45 | #include <atomic.h> |
46 | #include <atomic.h> |
46 | #include <synch/spinlock.h> |
47 | #include <synch/spinlock.h> |
47 | #include <config.h> |
48 | #include <config.h> |
Line 372... | Line 373... | ||
372 | spinlock_unlock(&THREAD->lock); |
373 | spinlock_unlock(&THREAD->lock); |
373 | thread_ready(THREAD); |
374 | thread_ready(THREAD); |
374 | break; |
375 | break; |
375 | 376 | ||
376 | case Exiting: |
377 | case Exiting: |
- | 378 | repeat: |
|
- | 379 | if (THREAD->detached) { |
|
377 | thread_destroy(THREAD); |
380 | thread_destroy(THREAD); |
- | 381 | } else { |
|
- | 382 | /* |
|
- | 383 | * The thread structure is kept allocated until somebody |
|
- | 384 | * calls thread_detach() on it. |
|
- | 385 | */ |
|
- | 386 | if (!spinlock_trylock(&THREAD->join_wq.lock)) { |
|
- | 387 | /* |
|
- | 388 | * Avoid deadlock. |
|
- | 389 | */ |
|
- | 390 | spinlock_unlock(&THREAD->lock); |
|
- | 391 | delay(10); |
|
- | 392 | spinlock_lock(&THREAD->lock); |
|
- | 393 | goto repeat; |
|
- | 394 | } |
|
- | 395 | _waitq_wakeup_unsafe(&THREAD->join_wq, false); |
|
- | 396 | spinlock_unlock(&THREAD->join_wq.lock); |
|
- | 397 | ||
- | 398 | THREAD->state = Undead; |
|
- | 399 | spinlock_unlock(&THREAD->lock); |
|
- | 400 | } |
|
378 | break; |
401 | break; |
379 | 402 | ||
380 | case Sleeping: |
403 | case Sleeping: |
381 | /* |
404 | /* |
382 | * Prefer the thread after it's woken up. |
405 | * Prefer the thread after it's woken up. |