X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/8ad349bb6ed4a0be06e34c92be0d98b92e078db4..89b3af67bb32e691275bf6fa803d1834b2284115:/osfmk/kern/wait_queue.h?ds=sidebyside diff --git a/osfmk/kern/wait_queue.h b/osfmk/kern/wait_queue.h index 5650b85e8..74c8fa6d7 100644 --- a/osfmk/kern/wait_queue.h +++ b/osfmk/kern/wait_queue.h @@ -1,31 +1,29 @@ /* * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. * - * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ + * @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. 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 - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and + * 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. 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 + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * 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_OSREFERENCE_HEADER_END@ + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ #ifdef KERNEL_PRIVATE @@ -157,13 +155,24 @@ typedef struct wait_queue_link { * 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, LockTimeOut * 2)) + panic("wait queue deadlock - wq=0x%x, cpu=%d\n", wq, cpu_number()); +} + +static inline void wait_queue_unlock(wait_queue_t wq) { + assert(wait_queue_held(wq)); +#if defined(__i386__) + /* 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)