]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/wait_queue.h
xnu-1228.9.59.tar.gz
[apple/xnu.git] / osfmk / kern / wait_queue.h
index 40955cb270c574afa75ca786079154456374dab6..5a1be3f35840fe896ef46d4469fddae7fcd4f2da 100644 (file)
@@ -1,16 +1,19 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_LICENSE_HEADER_START@
- * 
- * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
  * 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.
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ * 
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
  * 
  * The Original Code and all software distributed under the License are
  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * Please see the License for the specific language governing rights and
  * limitations under the License.
  * 
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
-#ifndef _KERN_WAIT_QUEUE_H_
-#define _KERN_WAIT_QUEUE_H_
 
-#include <sys/appleapiopts.h>
+#ifdef KERNEL_PRIVATE
 
-#ifdef __APPLE_API_PRIVATE
+#ifndef _KERN_WAIT_QUEUE_H_
+#define _KERN_WAIT_QUEUE_H_
 
+#include <mach/mach_types.h>
 #include <mach/sync_policy.h>
 #include <mach/kern_return.h>          /* for kern_return_t */
 
 #include <kern/kern_types.h>           /* for wait_queue_t */
 
-#ifdef MACH_KERNEL_PRIVATE
+#include <sys/cdefs.h>
+
+#ifdef MACH_KERNEL_PRIVATE
 
 #include <kern/lock.h>
 #include <kern/queue.h>
-
+#include <machine/cpu_number.h>
 
 /*
  *     wait_queue_t
@@ -118,7 +123,7 @@ typedef WaitQueueElement *wait_queue_element_t;
  *     with that port may wake up any thread from any of those portsets,
  *     or one that was waiting locally on the port itself.
  */
-typedef struct wait_queue_link {
+typedef struct _wait_queue_link {
        WaitQueueElement                wql_element;    /* element on master */
        queue_chain_t                   wql_setlinks;   /* element on set */
     wait_queue_set_t           wql_setqueue;   /* set queue */
@@ -141,22 +146,41 @@ typedef struct wait_queue_link {
        (((wq)->wq_type & ~1) == _WAIT_QUEUE_inited)
 
 #define wait_queue_empty(wq)   (queue_empty(&(wq)->wq_queue))
+
 #define wait_queue_held(wq)            (hw_lock_held(&(wq)->wq_interlock))
 #define wait_queue_lock_try(wq) (hw_lock_try(&(wq)->wq_interlock))
 
+/* For x86, the hardware timeout is in TSC units. */
+#if defined(i386)
+#define        hwLockTimeOut LockTimeOutTSC
+#else
+#define        hwLockTimeOut LockTimeOut
+#endif
 /*
  * Double the standard lock timeout, because wait queues tend
  * to iterate over a number of threads - locking each.  If there is
  * a problem with a thread lock, it normally times out at the wait
  * queue level first, hiding the real problem.
  */
-#define wait_queue_lock(wq)    \
-       ((void) (!hw_lock_to(&(wq)->wq_interlock, LockTimeOut * 2) ? \
-                panic("wait queue deadlock - wq=0x%x, cpu=%d\n", \
-                      wq, cpu_number()) : 0))
 
-#define wait_queue_unlock(wq) \
-       (assert(wait_queue_held(wq)), hw_lock_unlock(&(wq)->wq_interlock))
+static inline void wait_queue_lock(wait_queue_t wq) {
+       if (!hw_lock_to(&(wq)->wq_interlock, hwLockTimeOut * 2))
+               panic("wait queue deadlock - wq=%p, cpu=%d\n", wq, cpu_number(
+));
+}
+static inline void wait_queue_unlock(wait_queue_t wq) {
+       assert(wait_queue_held(wq));
+#if defined(__i386__)
+       /* DRK: On certain x86 systems, this spinlock is susceptible to
+        * lock starvation. Hence use an unlock variant which performs
+        * a cacheline flush to minimize cache affinity on acquisition.
+        */
+       i386_lock_unlock_with_flush(&(wq)->wq_interlock);
+#else
+       hw_lock_unlock(&(wq)->wq_interlock);
+#endif
+}
 
 #define wqs_lock(wqs)          wait_queue_lock(&(wqs)->wqs_wait_queue)
 #define wqs_unlock(wqs)                wait_queue_unlock(&(wqs)->wqs_wait_queue)
@@ -172,16 +196,10 @@ __private_extern__ wait_result_t wait_queue_assert_wait64_locked(
                        wait_queue_t wait_queue,
                        event64_t wait_event,
                        wait_interrupt_t interruptible,
-                       boolean_t unlock);
-
-/* peek to see which thread would be chosen for a wakeup - but keep on queue */
-__private_extern__ void wait_queue_peek64_locked(
-                       wait_queue_t wait_queue,
-                       event64_t event,
-                       thread_t *thread,
-                       wait_queue_t *found_queue);
+                       uint64_t deadline,
+                       thread_t thread);
 
-/* peek to see which thread would be chosen for a wakeup - but keep on queue */
+/* pull a thread from its wait queue */
 __private_extern__ void wait_queue_pull_thread_locked(
                        wait_queue_t wait_queue,
                        thread_t thread,
@@ -216,11 +234,15 @@ __private_extern__ kern_return_t wait_queue_wakeup64_thread_locked(
                        wait_result_t result,
                        boolean_t unlock);
 
-#endif /* MACH_KERNEL_PRIVATE */
+#endif /* MACH_KERNEL_PRIVATE */
+
+__BEGIN_DECLS
 
-#ifdef __APPLE_API_UNSTABLE
 /******** Semi-Public interfaces (not a part of a higher construct) ************/
 
+extern unsigned int wait_queue_set_size(void);
+extern unsigned int wait_queue_link_size(void);
+
 extern kern_return_t wait_queue_init(
                        wait_queue_t wait_queue,
                        int policy);
@@ -228,6 +250,10 @@ extern kern_return_t wait_queue_init(
 extern wait_queue_set_t wait_queue_set_alloc(
                        int policy);
 
+extern kern_return_t wait_queue_set_init(
+                       wait_queue_set_t set_queue,
+                       int policy);
+
 extern kern_return_t wait_queue_set_free(
                        wait_queue_set_t set_queue);
 
@@ -237,17 +263,16 @@ extern wait_queue_link_t wait_queue_link_alloc(
 extern kern_return_t wait_queue_link_free(
                        wait_queue_link_t link_element);
 
-#endif /* __APPLE_API_UNSTABLE */
-
-#ifdef __APPLE_API_EVOLVING
-
-extern wait_queue_t wait_queue_alloc(
-                       int policy);
+extern kern_return_t wait_queue_link(
+                       wait_queue_t wait_queue,
+                       wait_queue_set_t set_queue);
 
-extern kern_return_t wait_queue_free(
-                       wait_queue_t wait_queue);
+extern kern_return_t wait_queue_link_noalloc(
+                       wait_queue_t wait_queue,
+                       wait_queue_set_t set_queue,
+                       wait_queue_link_t link);
 
-extern kern_return_t wait_queue_link(
+extern boolean_t wait_queue_member(
                        wait_queue_t wait_queue,
                        wait_queue_set_t set_queue);
 
@@ -258,14 +283,35 @@ extern kern_return_t wait_queue_unlink(
 extern kern_return_t wait_queue_unlink_all(
                        wait_queue_t wait_queue);
 
+extern kern_return_t wait_queue_unlinkall_nofree(
+                       wait_queue_t wait_queue);
+
 extern kern_return_t wait_queue_set_unlink_all(
                        wait_queue_set_t set_queue);
 
+/* legacy API */
+kern_return_t wait_queue_sub_init(
+                       wait_queue_set_t set_queue,
+                       int policy);
+
+kern_return_t wait_queue_sub_clearrefs(
+                       wait_queue_set_t wq_set);
+
+extern kern_return_t wait_subqueue_unlink_all(
+                       wait_queue_set_t set_queue);
+
+extern wait_queue_t wait_queue_alloc(
+                       int policy);
+
+extern kern_return_t wait_queue_free(
+                       wait_queue_t wait_queue);
+
 /* assert intent to wait on <wait_queue,event64> pair */
 extern wait_result_t wait_queue_assert_wait64(
                        wait_queue_t wait_queue,
                        event64_t wait_event,
-                       wait_interrupt_t interruptible);
+                       wait_interrupt_t interruptible,
+                       uint64_t deadline);
 
 /* wakeup the most appropriate thread waiting on <wait_queue,event64> pair */
 extern kern_return_t wait_queue_wakeup64_one(
@@ -286,8 +332,6 @@ extern kern_return_t wait_queue_wakeup64_thread(
                        thread_t thread,
                        wait_result_t result);
 
-#endif  /* __APPLE_API_EVOLVING */
-
 /*
  * Compatibility Wait Queue APIs based on pointer events instead of 64bit
  * integer events.
@@ -297,7 +341,8 @@ extern kern_return_t wait_queue_wakeup64_thread(
 extern wait_result_t wait_queue_assert_wait(
                        wait_queue_t wait_queue,
                        event_t wait_event,
-                       wait_interrupt_t interruptible);
+                       wait_interrupt_t interruptible,
+                       uint64_t deadline);
 
 /* wakeup the most appropriate thread waiting on <wait_queue,event> pair */
 extern kern_return_t wait_queue_wakeup_one(
@@ -318,6 +363,8 @@ extern kern_return_t wait_queue_wakeup_thread(
                        thread_t thread,
                        wait_result_t result);
 
-#endif /* __APPLE_API_PRIVATE */
+__END_DECLS
+
+#endif /* _KERN_WAIT_QUEUE_H_ */
 
-#endif /* _KERN_WAIT_QUEUE_H_ */
+#endif /* KERNEL_PRIVATE */