X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/e5568f75972dfc723778653c11cb6b4dc825716a..ff6e181ae92fc6f1e89841290f461d1f2f9badd9:/osfmk/kern/thread_call.c diff --git a/osfmk/kern/thread_call.c b/osfmk/kern/thread_call.c index 365f4c2bf..20b9341eb 100644 --- a/osfmk/kern/thread_call.c +++ b/osfmk/kern/thread_call.c @@ -1,43 +1,39 @@ /* - * Copyright (c) 1993-1995, 1999-2000 Apple Computer, Inc. + * Copyright (c) 1993-1995, 1999-2005 Apple Computer, Inc. * All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * - * The contents of this file constitute Original Code as defined in and - * are subject to the Apple Public Source License Version 1.1 (the - * "License"). You may not use this file except in compliance with the - * License. Please obtain a copy of the License at - * http://www.apple.com/publicsource and read it before using this file. + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. * - * This Original Code and all software distributed under the License are - * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */ -/* - * Thread-based callout module. - * - * HISTORY - * - * 10 July 1999 (debo) - * Pulled into Mac OS X (microkernel). - * - * 3 July 1993 (debo) - * Created. - */ #include +#include +#include +#include #include #include #include #include +#include + +#include #include #include @@ -109,7 +105,7 @@ _delayed_call_dequeue( thread_call_t call ); -static void __inline__ +static __inline__ void _set_delayed_call_timer( thread_call_t call ); @@ -156,10 +152,12 @@ _delayed_call_timer( void thread_call_initialize(void) { - thread_call_t call; - spl_t s; + kern_return_t result; + thread_t thread; + thread_call_t call; + spl_t s; - simple_lock_init(&thread_call_lock, ETAP_MISC_TIMER); + simple_lock_init(&thread_call_lock, 0); s = splsched(); simple_lock(&thread_call_lock); @@ -186,7 +184,11 @@ thread_call_initialize(void) simple_unlock(&thread_call_lock); splx(s); - kernel_thread_with_priority(_activate_thread, MAXPRI_KERNEL - 2); + result = kernel_thread_start_priority((thread_continue_t)_activate_thread, NULL, MAXPRI_KERNEL - 2, &thread); + if (result != KERN_SUCCESS) + panic("thread_call_initialize"); + + thread_deallocate(thread); } void @@ -664,7 +666,7 @@ thread_call_free( simple_unlock(&thread_call_lock); splx(s); - kfree((vm_offset_t)call, sizeof (thread_call_data_t)); + kfree(call, sizeof (thread_call_data_t)); return (TRUE); } @@ -919,9 +921,7 @@ static __inline__ void _call_thread_wake(void) { - if (wait_queue_wakeup_one( - &call_thread_waitqueue, &call_thread_waitqueue, - THREAD_AWAKENED) == KERN_SUCCESS) { + if (wait_queue_wakeup_one(&call_thread_waitqueue, NULL, THREAD_AWAKENED) == KERN_SUCCESS) { thread_call_vars.idle_thread_num--; if (++thread_call_vars.active_num > thread_call_vars.active_hiwat) @@ -1001,7 +1001,7 @@ _call_thread_continue(void) (void) splsched(); simple_lock(&thread_call_lock); - self->active_callout = TRUE; + self->options |= TH_OPT_CALLOUT; while (thread_call_vars.pending_num > 0) { thread_call_t call; @@ -1034,7 +1034,7 @@ _call_thread_continue(void) simple_lock(&thread_call_lock); } - self->active_callout = FALSE; + self->options &= ~TH_OPT_CALLOUT; if (--thread_call_vars.active_num < thread_call_vars.active_lowat) thread_call_vars.active_lowat = thread_call_vars.active_num; @@ -1042,14 +1042,12 @@ _call_thread_continue(void) if (thread_call_vars.idle_thread_num < thread_call_vars.thread_lowat) { thread_call_vars.idle_thread_num++; - wait_queue_assert_wait( - &call_thread_waitqueue, &call_thread_waitqueue, - THREAD_INTERRUPTIBLE); + wait_queue_assert_wait(&call_thread_waitqueue, NULL, THREAD_UNINT, 0); simple_unlock(&thread_call_lock); (void) spllo(); - thread_block(_call_thread_continue); + thread_block((thread_continue_t)_call_thread_continue); /* NOTREACHED */ } @@ -1058,7 +1056,7 @@ _call_thread_continue(void) simple_unlock(&thread_call_lock); (void) spllo(); - (void) thread_terminate(self->top_act); + thread_terminate(self); /* NOTREACHED */ } @@ -1084,6 +1082,9 @@ static void _activate_thread_continue(void) { + kern_return_t result; + thread_t thread; + (void) splsched(); simple_lock(&thread_call_lock); @@ -1099,7 +1100,11 @@ _activate_thread_continue(void) simple_unlock(&thread_call_lock); (void) spllo(); - kernel_thread_with_priority(_call_thread, MAXPRI_KERNEL - 1); + result = kernel_thread_start_priority((thread_continue_t)_call_thread, NULL, MAXPRI_KERNEL - 1, &thread); + if (result != KERN_SUCCESS) + panic("activate_thread"); + + thread_deallocate(thread); (void) splsched(); simple_lock(&thread_call_lock); @@ -1111,7 +1116,7 @@ _activate_thread_continue(void) simple_unlock(&thread_call_lock); (void) spllo(); - thread_block(_activate_thread_continue); + thread_block((thread_continue_t)_activate_thread_continue); /* NOTREACHED */ } @@ -1121,7 +1126,7 @@ _activate_thread(void) { thread_t self = current_thread(); - self->vm_privilege = TRUE; + self->options |= TH_OPT_VMPRIV; vm_page_free_reserve(2); /* XXX */ _activate_thread_continue(); @@ -1131,8 +1136,8 @@ _activate_thread(void) static void _delayed_call_timer( - timer_call_param_t p0, - timer_call_param_t p1 + __unused timer_call_param_t p0, + __unused timer_call_param_t p1 ) { uint64_t timestamp;