Rev 1680 | Rev 1702 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 1680 | Rev 1687 | ||
|---|---|---|---|
| Line 348... | Line 348... | ||
| 348 | t->fpu_context_engaged = 0; |
348 | t->fpu_context_engaged = 0; |
| 349 | 349 | ||
| 350 | /* |
350 | /* |
| 351 | * Attach to the containing task. |
351 | * Attach to the containing task. |
| 352 | */ |
352 | */ |
| - | 353 | ipl = interrupts_disable(); |
|
| 353 | spinlock_lock(&task->lock); |
354 | spinlock_lock(&task->lock); |
| 354 | if (!task->accept_new_threads) { |
355 | if (!task->accept_new_threads) { |
| 355 | spinlock_unlock(&task->lock); |
356 | spinlock_unlock(&task->lock); |
| 356 | slab_free(thread_slab, t); |
357 | slab_free(thread_slab, t); |
| - | 358 | interrupts_restore(ipl); |
|
| 357 | return NULL; |
359 | return NULL; |
| 358 | } |
360 | } |
| 359 | list_append(&t->th_link, &task->th_head); |
361 | list_append(&t->th_link, &task->th_head); |
| 360 | if (task->refcount++ == 0) |
362 | if (task->refcount++ == 0) |
| 361 | task->main_thread = t; |
363 | task->main_thread = t; |
| 362 | spinlock_unlock(&task->lock); |
364 | spinlock_unlock(&task->lock); |
| 363 | 365 | ||
| 364 | /* |
366 | /* |
| 365 | * Register this thread in the system-wide list. |
367 | * Register this thread in the system-wide list. |
| 366 | */ |
368 | */ |
| 367 | ipl = interrupts_disable(); |
- | |
| 368 | spinlock_lock(&threads_lock); |
369 | spinlock_lock(&threads_lock); |
| 369 | btree_insert(&threads_btree, (btree_key_t) ((__address) t), (void *) t, NULL); |
370 | btree_insert(&threads_btree, (btree_key_t) ((__address) t), (void *) t, NULL); |
| 370 | spinlock_unlock(&threads_lock); |
371 | spinlock_unlock(&threads_lock); |
| 371 | 372 | ||
| 372 | interrupts_restore(ipl); |
373 | interrupts_restore(ipl); |
| 373 | 374 | ||
| 374 | return t; |
375 | return t; |
| 375 | } |
376 | } |
| 376 | 377 | ||
| 377 | /** Make thread exiting |
378 | /** Terminate thread. |
| 378 | * |
379 | * |
| 379 | * End current thread execution and switch it to the exiting |
380 | * End current thread execution and switch it to the exiting |
| 380 | * state. All pending timeouts are executed. |
381 | * state. All pending timeouts are executed. |
| 381 | * |
382 | * |
| 382 | */ |
383 | */ |
| Line 435... | Line 436... | ||
| 435 | * the thread pointer is guaranteed to be still valid. |
436 | * the thread pointer is guaranteed to be still valid. |
| 436 | */ |
437 | */ |
| 437 | 438 | ||
| 438 | ipl = interrupts_disable(); |
439 | ipl = interrupts_disable(); |
| 439 | spinlock_lock(&t->lock); |
440 | spinlock_lock(&t->lock); |
| 440 | - | ||
| 441 | ASSERT(!t->detached); |
441 | ASSERT(!t->detached); |
| 442 | - | ||
| 443 | (void) waitq_sleep_prepare(&t->join_wq); |
- | |
| 444 | spinlock_unlock(&t->lock); |
442 | spinlock_unlock(&t->lock); |
| 445 | - | ||
| 446 | rc = waitq_sleep_timeout_unsafe(&t->join_wq, usec, flags); |
- | |
| 447 | - | ||
| 448 | waitq_sleep_finish(&t->join_wq, rc, ipl); |
- | |
| 449 | interrupts_restore(ipl); |
443 | interrupts_restore(ipl); |
| 450 | 444 | ||
| - | 445 | rc = waitq_sleep_timeout(&t->join_wq, usec, flags); |
|
| - | 446 | ||
| 451 | return rc; |
447 | return rc; |
| 452 | } |
448 | } |
| 453 | 449 | ||
| 454 | /** Detach thread. |
450 | /** Detach thread. |
| 455 | * |
451 | * |
| Line 464... | Line 460... | ||
| 464 | 460 | ||
| 465 | /* |
461 | /* |
| 466 | * Since the thread is expected to not be already detached, |
462 | * Since the thread is expected to not be already detached, |
| 467 | * pointer to it must be still valid. |
463 | * pointer to it must be still valid. |
| 468 | */ |
464 | */ |
| 469 | - | ||
| 470 | ipl = interrupts_disable(); |
465 | ipl = interrupts_disable(); |
| 471 | spinlock_lock(&t->lock); |
466 | spinlock_lock(&t->lock); |
| 472 | ASSERT(!t->detached); |
467 | ASSERT(!t->detached); |
| 473 | if (t->state == Undead) { |
468 | if (t->state == Undead) { |
| 474 | thread_destroy(t); /* unlocks &t->lock */ |
469 | thread_destroy(t); /* unlocks &t->lock */ |