• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/xnu-2782.1.97/osfmk/kern/

Lines Matching refs:thread

63 #include <kern/thread.h>
88 * Internal routine to mark a thread as started.
89 * Always called with the thread locked.
95 * of the newly created thread. Commented out for now, in case we
100 thread_t thread)
102 clear_wait(thread, THREAD_AWAKENED);
103 thread->started = TRUE;
104 // DTRACE_PROC1(lwp__start, thread_t, thread);
108 * Internal routine to terminate a thread.
113 thread_t thread)
117 thread_mtx_lock(thread);
119 if (thread->active) {
120 thread->active = FALSE;
122 act_abort(thread);
124 if (thread->started)
125 clear_wait(thread, THREAD_INTERRUPTED);
127 thread_start_internal(thread);
133 if (thread->affinity_set != NULL)
134 thread_affinity_terminate(thread);
136 thread_mtx_unlock(thread);
138 if (thread != current_thread() && result == KERN_SUCCESS)
139 thread_wait(thread, FALSE);
145 * Terminate a thread.
149 thread_t thread)
153 if (thread == THREAD_NULL)
156 if ( thread->task == kernel_task &&
157 thread != current_thread() )
160 result = thread_terminate_internal(thread);
163 * If a kernel thread is terminating itself, force an AST here.
168 if (thread->task == kernel_task) {
178 * Suspend execution of the specified thread.
179 * This is a recursive-style suspension of the thread, a count of
182 * Called with thread mutex held.
186 register thread_t thread)
188 if (thread->suspend_count++ == 0) {
189 install_special_handler(thread);
190 if (thread->started)
191 thread_wakeup_one(&thread->suspend_count);
196 * Decrement internal suspension count, setting thread
199 * Called with thread mutex held.
203 register thread_t thread)
205 if ( thread->suspend_count > 0 &&
206 --thread->suspend_count == 0 ) {
207 if (thread->started)
208 thread_wakeup_one(&thread->suspend_count);
210 thread_start_internal(thread);
217 register thread_t thread)
222 if (thread == THREAD_NULL || thread->task == kernel_task)
225 thread_mtx_lock(thread);
227 if (thread->active) {
228 if ( thread->user_stop_count++ == 0 &&
229 thread->suspend_count++ == 0 ) {
230 install_special_handler(thread);
231 if (thread != self)
232 thread_wakeup_one(&thread->suspend_count);
238 thread_mtx_unlock(thread);
240 if (thread != self && result == KERN_SUCCESS)
241 thread_wait(thread, FALSE);
248 register thread_t thread)
252 if (thread == THREAD_NULL || thread->task == kernel_task)
255 thread_mtx_lock(thread);
257 if (thread->active) {
258 if (thread->user_stop_count > 0) {
259 if ( --thread->user_stop_count == 0 &&
260 --thread->suspend_count == 0 ) {
261 if (thread->started)
262 thread_wakeup_one(&thread->suspend_count);
264 thread_start_internal(thread);
274 thread_mtx_unlock(thread);
286 register thread_t thread)
290 if (thread == THREAD_NULL)
293 thread_mtx_lock(thread);
295 if (thread->active)
296 result = thread_depress_abort_internal(thread);
300 thread_mtx_unlock(thread);
310 * Called with thread mutex held.
314 thread_t thread)
318 thread_lock(thread);
320 if (!(thread->sched_flags & TH_SFLAG_ABORT)) {
321 thread->sched_flags |= TH_SFLAG_ABORT;
322 install_special_handler_locked(thread);
325 thread->sched_flags &= ~TH_SFLAG_ABORTSAFELY;
327 thread_unlock(thread);
333 register thread_t thread)
337 if (thread == THREAD_NULL)
340 thread_mtx_lock(thread);
342 if (thread->active) {
343 act_abort(thread);
344 clear_wait(thread, THREAD_INTERRUPTED);
349 thread_mtx_unlock(thread);
356 thread_t thread)
360 if (thread == THREAD_NULL)
363 thread_mtx_lock(thread);
365 if (thread->active) {
368 thread_lock(thread);
369 if (!thread->at_safe_point ||
370 clear_wait_internal(thread, THREAD_INTERRUPTED) != KERN_SUCCESS) {
371 if (!(thread->sched_flags & TH_SFLAG_ABORT)) {
372 thread->sched_flags |= TH_SFLAG_ABORTED_MASK;
373 install_special_handler_locked(thread);
376 thread_unlock(thread);
382 thread_mtx_unlock(thread);
394 thread_t thread,
401 if (thread == THREAD_NULL)
404 thread_mtx_lock(thread);
406 if (thread->active)
408 thread, flavor, thread_info_out, thread_info_count);
412 thread_mtx_unlock(thread);
419 register thread_t thread,
426 if (thread == THREAD_NULL)
429 thread_mtx_lock(thread);
431 if (thread->active) {
432 if (thread != current_thread()) {
433 thread_hold(thread);
435 thread_mtx_unlock(thread);
437 if (thread_stop(thread, FALSE)) {
438 thread_mtx_lock(thread);
440 thread, flavor, state, state_count);
441 thread_unstop(thread);
444 thread_mtx_lock(thread);
448 thread_release(thread);
452 thread, flavor, state, state_count);
457 thread_mtx_unlock(thread);
463 * Change thread's machine-dependent state. Called with nothing
468 register thread_t thread,
476 if (thread == THREAD_NULL)
479 thread_mtx_lock(thread);
481 if (thread->active) {
482 if (thread != current_thread()) {
483 thread_hold(thread);
485 thread_mtx_unlock(thread);
487 if (thread_stop(thread, TRUE)) {
488 thread_mtx_lock(thread);
490 thread, flavor, state, state_count);
491 thread_unstop(thread);
494 thread_mtx_lock(thread);
498 thread_release(thread);
502 thread, flavor, state, state_count);
508 extmod_statistics_incr_thread_set_state(thread);
510 thread_mtx_unlock(thread);
518 register thread_t thread,
525 register thread_t thread,
530 return thread_set_state_internal(thread, flavor, state, state_count, FALSE);
535 register thread_t thread,
540 return thread_set_state_internal(thread, flavor, state, state_count, TRUE);
544 * Kernel-internal "thread" interfaces used outside this file:
547 /* Initialize (or re-initialize) a thread state. Called from execve
552 register thread_t thread)
556 if (thread == THREAD_NULL)
559 thread_mtx_lock(thread);
561 if (thread->active) {
562 if (thread != current_thread()) {
563 thread_hold(thread);
565 thread_mtx_unlock(thread);
567 if (thread_stop(thread, TRUE)) {
568 thread_mtx_lock(thread);
569 result = machine_thread_state_initialize( thread );
570 thread_unstop(thread);
573 thread_mtx_lock(thread);
577 thread_release(thread);
580 result = machine_thread_state_initialize( thread );
585 thread_mtx_unlock(thread);
634 * Set the status of the specified thread.
639 register thread_t thread,
645 return (thread_set_state(thread, flavor, tstate, count));
651 * Get the status of the specified thread.
655 register thread_t thread,
660 return (thread_get_state(thread, flavor, tstate, count));
664 * Change thread's machine-dependent userspace TSD base.
669 thread_t thread,
674 if (thread == THREAD_NULL)
677 thread_mtx_lock(thread);
679 if (thread->active) {
680 if (thread != current_thread()) {
681 thread_hold(thread);
683 thread_mtx_unlock(thread);
685 if (thread_stop(thread, TRUE)) {
686 thread_mtx_lock(thread);
687 result = machine_thread_set_tsd_base(thread, tsd_base);
688 thread_unstop(thread);
691 thread_mtx_lock(thread);
695 thread_release(thread);
698 result = machine_thread_set_tsd_base(thread, tsd_base);
703 thread_mtx_unlock(thread);
714 * Called with the thread mutex held.
718 thread_t thread)
722 thread_lock(thread);
723 install_special_handler_locked(thread);
724 thread_unlock(thread);
733 * Called with the thread mutex and scheduling lock held.
737 thread_t thread)
743 for (rh = &thread->handlers; *rh; rh = &(*rh)->next)
746 if (rh != &thread->special_handler.next)
747 *rh = &thread->special_handler;
754 if (thread->sched_flags & TH_SFLAG_DEPRESSED_MASK)
755 SCHED(compute_priority)(thread, TRUE);
757 thread_ast_set(thread, AST_APC);
759 if (thread == current_thread())
760 ast_propagate(thread->ast);
762 processor_t processor = thread->last_processor;
766 processor->active_thread == thread )
778 thread_t thread = current_thread();
780 thread_ast_clear(thread, AST_APC);
786 thread_mtx_lock(thread);
789 thread_lock(thread);
791 rh = thread->handlers;
793 thread->handlers = rh->next;
795 thread_unlock(thread);
798 thread_mtx_unlock(thread);
801 (*rh->handler)(rh, thread);
807 thread_unlock(thread);
810 thread_mtx_unlock(thread);
825 thread_t thread = current_thread();
827 thread_mtx_lock(thread);
829 if (thread->suspend_count > 0)
830 install_special_handler(thread);
834 thread_lock(thread);
835 if (thread->sched_flags & TH_SFLAG_DEPRESSED_MASK) {
836 processor_t myprocessor = thread->last_processor;
838 thread->sched_pri = DEPRESSPRI;
839 myprocessor->current_pri = thread->sched_pri;
841 thread_unlock(thread);
845 thread_mtx_unlock(thread);
858 thread_t thread)
862 thread_mtx_lock(thread);
865 thread_lock(thread);
866 thread->sched_flags &= ~TH_SFLAG_ABORTED_MASK;
867 thread_unlock(thread);
873 if (thread->active) {
874 if (thread->suspend_count > 0) {
875 if (thread->handlers == NULL) {
876 assert_wait(&thread->suspend_count, THREAD_ABORTSAFE);
877 thread_mtx_unlock(thread);
882 thread_mtx_unlock(thread);
889 thread_mtx_unlock(thread);
895 thread_mtx_unlock(thread);
901 thread_t thread,
908 thread_t thread,
913 if (thread == current_thread())
916 return (thread_set_state(thread, flavor, state, count));
922 thread_t thread,
927 if (thread == current_thread())
930 return (thread_set_state_from_user(thread, flavor, state, count));
936 thread_t thread,
941 if (thread == current_thread())
944 return (thread_get_state(thread, flavor, state, count));
949 thread_t thread,
954 if (thread == current_thread()) {
955 thread_ast_set(thread, ast);
956 ast_propagate(thread->ast);
961 thread_lock(thread);
962 thread_ast_set(thread, ast);
963 processor = thread->last_processor;
966 processor->active_thread == thread )
968 thread_unlock(thread);
976 thread_t thread)
978 act_set_ast( thread, AST_BSD );
983 thread_t thread)
985 act_set_ast( thread, AST_APC );
990 thread_t thread)
993 if (thread != current_thread())
997 act_set_ast( thread, AST_KPERF );
1003 thread_t thread)
1005 act_set_ast( thread, AST_MACF);