]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/thread_call.c
xnu-792.6.56.tar.gz
[apple/xnu.git] / osfmk / kern / thread_call.c
index a34caf6ec718d4c6b8186ec47958c4f29c49dd1e..20b9341eb28e5d92c53785bbac50b36570606be0 100644 (file)
@@ -1,11 +1,9 @@
 /*
- * 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@
  * 
- * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
- * 
  * 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
  * 
  * @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 <mach/mach_types.h>
+#include <mach/thread_act.h>
 
+#include <kern/kern_types.h>
+#include <kern/kalloc.h>
 #include <kern/sched_prim.h>
 #include <kern/clock.h>
 #include <kern/task.h>
 #include <kern/thread.h>
+#include <kern/wait_queue.h>
+
+#include <vm/vm_pageout.h>
 
 #include <kern/thread_call.h>
 #include <kern/call_entry.h>
@@ -112,7 +105,7 @@ _delayed_call_dequeue(
        thread_call_t           call
 );
 
-static void __inline__
+static __inline__ void
 _set_delayed_call_timer(
        thread_call_t           call
 );
@@ -159,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);
@@ -189,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
@@ -667,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);
 }
@@ -922,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)
@@ -1004,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;
@@ -1037,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;
@@ -1045,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 */
     }
     
@@ -1061,7 +1056,7 @@ _call_thread_continue(void)
     simple_unlock(&thread_call_lock);
     (void) spllo();
     
-    (void) thread_terminate(self->top_act);
+    thread_terminate(self);
        /* NOTREACHED */
 }
 
@@ -1087,6 +1082,9 @@ static
 void
 _activate_thread_continue(void)
 {
+       kern_return_t   result;
+       thread_t                thread;
+
     (void) splsched();
     simple_lock(&thread_call_lock);
         
@@ -1102,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);
@@ -1114,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 */
 }
 
@@ -1124,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();
@@ -1134,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;