/* * Internal routine to terminate a thread. * Sometimes called with task already locked. */ kern_return_t thread_terminate_internal( thread_t thread) { kern_return_t result = KERN_SUCCESS; thread_mtx_lock(thread); if (thread->active) { thread->active = FALSE; act_abort(thread); if (thread->started) clear_wait(thread, THREAD_INTERRUPTED); else { thread_start_internal(thread); } } else result = KERN_TERMINATED; if (thread->affinity_set != NULL) thread_affinity_terminate(thread); thread_mtx_unlock(thread); if (thread != current_thread() && result == KERN_SUCCESS) thread_wait(thread, FALSE); return (result); }
kern_return_t thread_abort( register thread_t thread) { kern_return_t result = KERN_SUCCESS; if (thread == THREAD_NULL) return (KERN_INVALID_ARGUMENT); thread_mtx_lock(thread); if (thread->active) { act_abort(thread); clear_wait(thread, THREAD_INTERRUPTED); } else result = KERN_TERMINATED; thread_mtx_unlock(thread); return (result); }
/* * Internal routine to terminate a thread. * Sometimes called with task already locked. */ kern_return_t thread_terminate_internal( register thread_act_t act) { kern_return_t result; thread_t thread; thread = act_lock_thread(act); if (!act->active) { act_unlock_thread(act); return (KERN_TERMINATED); } act_disable(act); result = act_abort(act, FALSE); /* * Make sure this thread enters the kernel * Must unlock the act, but leave the shuttle * captured in this act. */ if (thread != current_thread()) { act_unlock(act); if (thread_stop(thread)) thread_unstop(thread); else result = KERN_ABORTED; act_lock(act); } clear_wait(thread, act->started? THREAD_INTERRUPTED: THREAD_AWAKENED); act_unlock_thread(act); return (result); }
kern_return_t thread_abort( register thread_act_t act) { kern_return_t result; thread_t thread; if (act == THR_ACT_NULL) return (KERN_INVALID_ARGUMENT); thread = act_lock_thread(act); if (!act->active) { act_unlock_thread(act); return (KERN_TERMINATED); } result = act_abort(act, FALSE); clear_wait(thread, THREAD_INTERRUPTED); act_unlock_thread(act); return (result); }