* Allocate a thread. */
| 711 | * Allocate a thread. |
| 712 | */ |
| 713 | struct thread * |
| 714 | thread_alloc(int pages) |
| 715 | { |
| 716 | struct thread *td; |
| 717 | lwpid_t tid; |
| 718 | |
| 719 | if (!thread_count_inc()) { |
| 720 | return (NULL); |
| 721 | } |
| 722 | |
| 723 | tid = tid_alloc(); |
| 724 | td = uma_zalloc(thread_zone, M_WAITOK); |
| 725 | KASSERT(td->td_kstack == 0, ("thread_alloc got thread with kstack")); |
| 726 | if (!vm_thread_new(td, pages)) { |
| 727 | uma_zfree(thread_zone, td); |
| 728 | tid_free(tid); |
| 729 | thread_count_dec(); |
| 730 | return (NULL); |
| 731 | } |
| 732 | td->td_tid = tid; |
| 733 | cpu_thread_alloc(td); |
| 734 | EVENTHANDLER_DIRECT_INVOKE(thread_ctor, td); |
| 735 | return (td); |
| 736 | } |
| 737 | |
| 738 | int |
| 739 | thread_alloc_stack(struct thread *td, int pages) |
no test coverage detected