xref: /xnu-10002.61.3/iokit/Kernel/IOLocks.cpp (revision 0f4c859e951fba394238ab619495c4e1d54d0f34)
1*0f4c859eSApple OSS Distributions /*
2*0f4c859eSApple OSS Distributions  * Copyright (c) 1998-2007 Apple Inc. All rights reserved.
3*0f4c859eSApple OSS Distributions  *
4*0f4c859eSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*0f4c859eSApple OSS Distributions  *
6*0f4c859eSApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*0f4c859eSApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*0f4c859eSApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*0f4c859eSApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*0f4c859eSApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*0f4c859eSApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*0f4c859eSApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*0f4c859eSApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*0f4c859eSApple OSS Distributions  *
15*0f4c859eSApple OSS Distributions  * Please obtain a copy of the License at
16*0f4c859eSApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*0f4c859eSApple OSS Distributions  *
18*0f4c859eSApple OSS Distributions  * The Original Code and all software distributed under the License are
19*0f4c859eSApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*0f4c859eSApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*0f4c859eSApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*0f4c859eSApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*0f4c859eSApple OSS Distributions  * Please see the License for the specific language governing rights and
24*0f4c859eSApple OSS Distributions  * limitations under the License.
25*0f4c859eSApple OSS Distributions  *
26*0f4c859eSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*0f4c859eSApple OSS Distributions  */
28*0f4c859eSApple OSS Distributions 
29*0f4c859eSApple OSS Distributions #include <IOKit/system.h>
30*0f4c859eSApple OSS Distributions 
31*0f4c859eSApple OSS Distributions #include <IOKit/IOReturn.h>
32*0f4c859eSApple OSS Distributions #include <IOKit/IOLib.h>
33*0f4c859eSApple OSS Distributions #include <IOKit/assert.h>
34*0f4c859eSApple OSS Distributions 
35*0f4c859eSApple OSS Distributions #include <IOKit/IOLocksPrivate.h>
36*0f4c859eSApple OSS Distributions 
37*0f4c859eSApple OSS Distributions extern "C" {
38*0f4c859eSApple OSS Distributions #include <kern/locks.h>
39*0f4c859eSApple OSS Distributions 
40*0f4c859eSApple OSS Distributions #if defined(__x86_64__)
41*0f4c859eSApple OSS Distributions /* Synthetic event if none is specified, for backwards compatibility only. */
42*0f4c859eSApple OSS Distributions static bool IOLockSleep_NO_EVENT __attribute__((used)) = 0;
43*0f4c859eSApple OSS Distributions #endif
44*0f4c859eSApple OSS Distributions 
45*0f4c859eSApple OSS Distributions void
IOLockInitWithState(IOLock * lock,IOLockState state)46*0f4c859eSApple OSS Distributions IOLockInitWithState( IOLock * lock, IOLockState state)
47*0f4c859eSApple OSS Distributions {
48*0f4c859eSApple OSS Distributions 	if (state == kIOLockStateLocked) {
49*0f4c859eSApple OSS Distributions 		lck_mtx_lock( lock);
50*0f4c859eSApple OSS Distributions 	}
51*0f4c859eSApple OSS Distributions }
52*0f4c859eSApple OSS Distributions 
53*0f4c859eSApple OSS Distributions IOLock *
IOLockAlloc(void)54*0f4c859eSApple OSS Distributions IOLockAlloc( void )
55*0f4c859eSApple OSS Distributions {
56*0f4c859eSApple OSS Distributions 	return lck_mtx_alloc_init(IOLockGroup, LCK_ATTR_NULL);
57*0f4c859eSApple OSS Distributions }
58*0f4c859eSApple OSS Distributions 
59*0f4c859eSApple OSS Distributions void
IOLockInlineInit(IOLock * lock)60*0f4c859eSApple OSS Distributions IOLockInlineInit( IOLock *lock )
61*0f4c859eSApple OSS Distributions {
62*0f4c859eSApple OSS Distributions 	lck_mtx_init(lock, IOLockGroup, LCK_ATTR_NULL);
63*0f4c859eSApple OSS Distributions }
64*0f4c859eSApple OSS Distributions 
65*0f4c859eSApple OSS Distributions void
IOLockInlineDestroy(IOLock * lock)66*0f4c859eSApple OSS Distributions IOLockInlineDestroy( IOLock * lock)
67*0f4c859eSApple OSS Distributions {
68*0f4c859eSApple OSS Distributions 	lck_mtx_destroy( lock, IOLockGroup);
69*0f4c859eSApple OSS Distributions }
70*0f4c859eSApple OSS Distributions 
71*0f4c859eSApple OSS Distributions void
IOLockFree(IOLock * lock)72*0f4c859eSApple OSS Distributions IOLockFree( IOLock * lock)
73*0f4c859eSApple OSS Distributions {
74*0f4c859eSApple OSS Distributions 	lck_mtx_free( lock, IOLockGroup);
75*0f4c859eSApple OSS Distributions }
76*0f4c859eSApple OSS Distributions 
77*0f4c859eSApple OSS Distributions lck_mtx_t *
IOLockGetMachLock(IOLock * lock)78*0f4c859eSApple OSS Distributions IOLockGetMachLock( IOLock * lock)
79*0f4c859eSApple OSS Distributions {
80*0f4c859eSApple OSS Distributions 	return (lck_mtx_t *)lock;
81*0f4c859eSApple OSS Distributions }
82*0f4c859eSApple OSS Distributions 
83*0f4c859eSApple OSS Distributions int
IOLockSleep(IOLock * lock,void * event,UInt32 interType)84*0f4c859eSApple OSS Distributions IOLockSleep( IOLock * lock, void *event, UInt32 interType)
85*0f4c859eSApple OSS Distributions {
86*0f4c859eSApple OSS Distributions 	return (int) lck_mtx_sleep(lock, LCK_SLEEP_PROMOTED_PRI, (event_t) event, (wait_interrupt_t) interType);
87*0f4c859eSApple OSS Distributions }
88*0f4c859eSApple OSS Distributions 
89*0f4c859eSApple OSS Distributions int
IOLockSleepDeadline(IOLock * lock,void * event,AbsoluteTime deadline,UInt32 interType)90*0f4c859eSApple OSS Distributions IOLockSleepDeadline( IOLock * lock, void *event,
91*0f4c859eSApple OSS Distributions     AbsoluteTime deadline, UInt32 interType)
92*0f4c859eSApple OSS Distributions {
93*0f4c859eSApple OSS Distributions 	return (int) lck_mtx_sleep_deadline(lock, LCK_SLEEP_PROMOTED_PRI, (event_t) event,
94*0f4c859eSApple OSS Distributions 	           (wait_interrupt_t) interType, __OSAbsoluteTime(deadline));
95*0f4c859eSApple OSS Distributions }
96*0f4c859eSApple OSS Distributions 
97*0f4c859eSApple OSS Distributions void
IOLockWakeup(IOLock * lock,void * event,bool oneThread)98*0f4c859eSApple OSS Distributions IOLockWakeup(IOLock * lock, void *event, bool oneThread)
99*0f4c859eSApple OSS Distributions {
100*0f4c859eSApple OSS Distributions 	thread_wakeup_prim((event_t) event, oneThread, THREAD_AWAKENED);
101*0f4c859eSApple OSS Distributions }
102*0f4c859eSApple OSS Distributions 
103*0f4c859eSApple OSS Distributions 
104*0f4c859eSApple OSS Distributions #if defined(__x86_64__)
105*0f4c859eSApple OSS Distributions /*
106*0f4c859eSApple OSS Distributions  * For backwards compatibility, kexts built against pre-Darwin 14 headers will bind at runtime to this function,
107*0f4c859eSApple OSS Distributions  * which supports a NULL event,
108*0f4c859eSApple OSS Distributions  */
109*0f4c859eSApple OSS Distributions int     IOLockSleep_legacy_x86_64( IOLock * lock, void *event, UInt32 interType) __asm("_IOLockSleep");
110*0f4c859eSApple OSS Distributions int     IOLockSleepDeadline_legacy_x86_64( IOLock * lock, void *event,
111*0f4c859eSApple OSS Distributions     AbsoluteTime deadline, UInt32 interType) __asm("_IOLockSleepDeadline");
112*0f4c859eSApple OSS Distributions void    IOLockWakeup_legacy_x86_64(IOLock * lock, void *event, bool oneThread) __asm("_IOLockWakeup");
113*0f4c859eSApple OSS Distributions 
114*0f4c859eSApple OSS Distributions int
IOLockSleep_legacy_x86_64(IOLock * lock,void * event,UInt32 interType)115*0f4c859eSApple OSS Distributions IOLockSleep_legacy_x86_64( IOLock * lock, void *event, UInt32 interType)
116*0f4c859eSApple OSS Distributions {
117*0f4c859eSApple OSS Distributions 	if (event == NULL) {
118*0f4c859eSApple OSS Distributions 		event = (void *)&IOLockSleep_NO_EVENT;
119*0f4c859eSApple OSS Distributions 	}
120*0f4c859eSApple OSS Distributions 
121*0f4c859eSApple OSS Distributions 	return IOLockSleep(lock, event, interType);
122*0f4c859eSApple OSS Distributions }
123*0f4c859eSApple OSS Distributions 
124*0f4c859eSApple OSS Distributions int
IOLockSleepDeadline_legacy_x86_64(IOLock * lock,void * event,AbsoluteTime deadline,UInt32 interType)125*0f4c859eSApple OSS Distributions IOLockSleepDeadline_legacy_x86_64( IOLock * lock, void *event,
126*0f4c859eSApple OSS Distributions     AbsoluteTime deadline, UInt32 interType)
127*0f4c859eSApple OSS Distributions {
128*0f4c859eSApple OSS Distributions 	if (event == NULL) {
129*0f4c859eSApple OSS Distributions 		event = (void *)&IOLockSleep_NO_EVENT;
130*0f4c859eSApple OSS Distributions 	}
131*0f4c859eSApple OSS Distributions 
132*0f4c859eSApple OSS Distributions 	return IOLockSleepDeadline(lock, event, deadline, interType);
133*0f4c859eSApple OSS Distributions }
134*0f4c859eSApple OSS Distributions 
135*0f4c859eSApple OSS Distributions void
IOLockWakeup_legacy_x86_64(IOLock * lock,void * event,bool oneThread)136*0f4c859eSApple OSS Distributions IOLockWakeup_legacy_x86_64(IOLock * lock, void *event, bool oneThread)
137*0f4c859eSApple OSS Distributions {
138*0f4c859eSApple OSS Distributions 	if (event == NULL) {
139*0f4c859eSApple OSS Distributions 		event = (void *)&IOLockSleep_NO_EVENT;
140*0f4c859eSApple OSS Distributions 	}
141*0f4c859eSApple OSS Distributions 
142*0f4c859eSApple OSS Distributions 	IOLockWakeup(lock, event, oneThread);
143*0f4c859eSApple OSS Distributions }
144*0f4c859eSApple OSS Distributions #endif /* defined(__x86_64__) */
145*0f4c859eSApple OSS Distributions 
146*0f4c859eSApple OSS Distributions 
147*0f4c859eSApple OSS Distributions struct _IORecursiveLock {
148*0f4c859eSApple OSS Distributions 	lck_mtx_t       mutex;
149*0f4c859eSApple OSS Distributions 	lck_grp_t       *group;
150*0f4c859eSApple OSS Distributions 	thread_t        thread;
151*0f4c859eSApple OSS Distributions 	UInt32          count;
152*0f4c859eSApple OSS Distributions };
153*0f4c859eSApple OSS Distributions 
154*0f4c859eSApple OSS Distributions IORecursiveLock *
IORecursiveLockAllocWithLockGroup(lck_grp_t * lockGroup)155*0f4c859eSApple OSS Distributions IORecursiveLockAllocWithLockGroup( lck_grp_t * lockGroup )
156*0f4c859eSApple OSS Distributions {
157*0f4c859eSApple OSS Distributions 	_IORecursiveLock * lock;
158*0f4c859eSApple OSS Distributions 
159*0f4c859eSApple OSS Distributions 	if (lockGroup == NULL) {
160*0f4c859eSApple OSS Distributions 		return NULL;
161*0f4c859eSApple OSS Distributions 	}
162*0f4c859eSApple OSS Distributions 
163*0f4c859eSApple OSS Distributions 	lock = IOMallocType( _IORecursiveLock );
164*0f4c859eSApple OSS Distributions 	if (!lock) {
165*0f4c859eSApple OSS Distributions 		return NULL;
166*0f4c859eSApple OSS Distributions 	}
167*0f4c859eSApple OSS Distributions 
168*0f4c859eSApple OSS Distributions 	lck_mtx_init( &lock->mutex, lockGroup, LCK_ATTR_NULL );
169*0f4c859eSApple OSS Distributions 	lock->group = lockGroup;
170*0f4c859eSApple OSS Distributions 	lock->thread = NULL;
171*0f4c859eSApple OSS Distributions 	lock->count  = 0;
172*0f4c859eSApple OSS Distributions 
173*0f4c859eSApple OSS Distributions 	return (IORecursiveLock *) lock;
174*0f4c859eSApple OSS Distributions }
175*0f4c859eSApple OSS Distributions 
176*0f4c859eSApple OSS Distributions 
177*0f4c859eSApple OSS Distributions IORecursiveLock *
IORecursiveLockAlloc(void)178*0f4c859eSApple OSS Distributions IORecursiveLockAlloc( void )
179*0f4c859eSApple OSS Distributions {
180*0f4c859eSApple OSS Distributions 	return IORecursiveLockAllocWithLockGroup( IOLockGroup );
181*0f4c859eSApple OSS Distributions }
182*0f4c859eSApple OSS Distributions 
183*0f4c859eSApple OSS Distributions void
IORecursiveLockFree(IORecursiveLock * _lock)184*0f4c859eSApple OSS Distributions IORecursiveLockFree( IORecursiveLock * _lock )
185*0f4c859eSApple OSS Distributions {
186*0f4c859eSApple OSS Distributions 	_IORecursiveLock * lock = (_IORecursiveLock *)_lock;
187*0f4c859eSApple OSS Distributions 
188*0f4c859eSApple OSS Distributions 	lck_mtx_destroy(&lock->mutex, lock->group);
189*0f4c859eSApple OSS Distributions 	IOFreeType( lock, _IORecursiveLock );
190*0f4c859eSApple OSS Distributions }
191*0f4c859eSApple OSS Distributions 
192*0f4c859eSApple OSS Distributions lck_mtx_t *
IORecursiveLockGetMachLock(IORecursiveLock * lock)193*0f4c859eSApple OSS Distributions IORecursiveLockGetMachLock( IORecursiveLock * lock )
194*0f4c859eSApple OSS Distributions {
195*0f4c859eSApple OSS Distributions 	return &lock->mutex;
196*0f4c859eSApple OSS Distributions }
197*0f4c859eSApple OSS Distributions 
198*0f4c859eSApple OSS Distributions void
IORecursiveLockLock(IORecursiveLock * _lock)199*0f4c859eSApple OSS Distributions IORecursiveLockLock( IORecursiveLock * _lock)
200*0f4c859eSApple OSS Distributions {
201*0f4c859eSApple OSS Distributions 	_IORecursiveLock * lock = (_IORecursiveLock *)_lock;
202*0f4c859eSApple OSS Distributions 
203*0f4c859eSApple OSS Distributions 	if (lock->thread == IOThreadSelf()) {
204*0f4c859eSApple OSS Distributions 		lock->count++;
205*0f4c859eSApple OSS Distributions 	} else {
206*0f4c859eSApple OSS Distributions 		lck_mtx_lock( &lock->mutex );
207*0f4c859eSApple OSS Distributions 		assert( lock->thread == NULL );
208*0f4c859eSApple OSS Distributions 		assert( lock->count == 0 );
209*0f4c859eSApple OSS Distributions 		lock->thread = IOThreadSelf();
210*0f4c859eSApple OSS Distributions 		lock->count = 1;
211*0f4c859eSApple OSS Distributions 	}
212*0f4c859eSApple OSS Distributions }
213*0f4c859eSApple OSS Distributions 
214*0f4c859eSApple OSS Distributions boolean_t
IORecursiveLockTryLock(IORecursiveLock * _lock)215*0f4c859eSApple OSS Distributions IORecursiveLockTryLock( IORecursiveLock * _lock)
216*0f4c859eSApple OSS Distributions {
217*0f4c859eSApple OSS Distributions 	_IORecursiveLock * lock = (_IORecursiveLock *)_lock;
218*0f4c859eSApple OSS Distributions 
219*0f4c859eSApple OSS Distributions 	if (lock->thread == IOThreadSelf()) {
220*0f4c859eSApple OSS Distributions 		lock->count++;
221*0f4c859eSApple OSS Distributions 		return true;
222*0f4c859eSApple OSS Distributions 	} else {
223*0f4c859eSApple OSS Distributions 		if (lck_mtx_try_lock( &lock->mutex )) {
224*0f4c859eSApple OSS Distributions 			assert( lock->thread == NULL );
225*0f4c859eSApple OSS Distributions 			assert( lock->count == 0 );
226*0f4c859eSApple OSS Distributions 			lock->thread = IOThreadSelf();
227*0f4c859eSApple OSS Distributions 			lock->count = 1;
228*0f4c859eSApple OSS Distributions 			return true;
229*0f4c859eSApple OSS Distributions 		}
230*0f4c859eSApple OSS Distributions 	}
231*0f4c859eSApple OSS Distributions 	return false;
232*0f4c859eSApple OSS Distributions }
233*0f4c859eSApple OSS Distributions 
234*0f4c859eSApple OSS Distributions void
IORecursiveLockUnlock(IORecursiveLock * _lock)235*0f4c859eSApple OSS Distributions IORecursiveLockUnlock( IORecursiveLock * _lock)
236*0f4c859eSApple OSS Distributions {
237*0f4c859eSApple OSS Distributions 	_IORecursiveLock * lock = (_IORecursiveLock *)_lock;
238*0f4c859eSApple OSS Distributions 
239*0f4c859eSApple OSS Distributions 	assert( lock->thread == IOThreadSelf());
240*0f4c859eSApple OSS Distributions 
241*0f4c859eSApple OSS Distributions 	if (0 == (--lock->count)) {
242*0f4c859eSApple OSS Distributions 		lock->thread = NULL;
243*0f4c859eSApple OSS Distributions 		lck_mtx_unlock( &lock->mutex );
244*0f4c859eSApple OSS Distributions 	}
245*0f4c859eSApple OSS Distributions }
246*0f4c859eSApple OSS Distributions 
247*0f4c859eSApple OSS Distributions boolean_t
IORecursiveLockHaveLock(const IORecursiveLock * _lock)248*0f4c859eSApple OSS Distributions IORecursiveLockHaveLock( const IORecursiveLock * _lock)
249*0f4c859eSApple OSS Distributions {
250*0f4c859eSApple OSS Distributions 	_IORecursiveLock * lock = (_IORecursiveLock *)_lock;
251*0f4c859eSApple OSS Distributions 
252*0f4c859eSApple OSS Distributions 	return lock->thread == IOThreadSelf();
253*0f4c859eSApple OSS Distributions }
254*0f4c859eSApple OSS Distributions 
255*0f4c859eSApple OSS Distributions int
IORecursiveLockSleep(IORecursiveLock * _lock,void * event,UInt32 interType)256*0f4c859eSApple OSS Distributions IORecursiveLockSleep(IORecursiveLock *_lock, void *event, UInt32 interType)
257*0f4c859eSApple OSS Distributions {
258*0f4c859eSApple OSS Distributions 	_IORecursiveLock * lock = (_IORecursiveLock *)_lock;
259*0f4c859eSApple OSS Distributions 	UInt32 count = lock->count;
260*0f4c859eSApple OSS Distributions 	int res;
261*0f4c859eSApple OSS Distributions 
262*0f4c859eSApple OSS Distributions 	assert(lock->thread == IOThreadSelf());
263*0f4c859eSApple OSS Distributions 
264*0f4c859eSApple OSS Distributions 	lock->count = 0;
265*0f4c859eSApple OSS Distributions 	lock->thread = NULL;
266*0f4c859eSApple OSS Distributions 	res = lck_mtx_sleep(&lock->mutex, LCK_SLEEP_PROMOTED_PRI, (event_t) event, (wait_interrupt_t) interType);
267*0f4c859eSApple OSS Distributions 
268*0f4c859eSApple OSS Distributions 	// Must re-establish the recursive lock no matter why we woke up
269*0f4c859eSApple OSS Distributions 	// otherwise we would potentially leave the return path corrupted.
270*0f4c859eSApple OSS Distributions 	assert(lock->thread == NULL);
271*0f4c859eSApple OSS Distributions 	assert(lock->count == 0);
272*0f4c859eSApple OSS Distributions 	lock->thread = IOThreadSelf();
273*0f4c859eSApple OSS Distributions 	lock->count = count;
274*0f4c859eSApple OSS Distributions 	return res;
275*0f4c859eSApple OSS Distributions }
276*0f4c859eSApple OSS Distributions 
277*0f4c859eSApple OSS Distributions int
IORecursiveLockSleepDeadline(IORecursiveLock * _lock,void * event,AbsoluteTime deadline,UInt32 interType)278*0f4c859eSApple OSS Distributions IORecursiveLockSleepDeadline( IORecursiveLock * _lock, void *event,
279*0f4c859eSApple OSS Distributions     AbsoluteTime deadline, UInt32 interType)
280*0f4c859eSApple OSS Distributions {
281*0f4c859eSApple OSS Distributions 	_IORecursiveLock * lock = (_IORecursiveLock *)_lock;
282*0f4c859eSApple OSS Distributions 	UInt32 count = lock->count;
283*0f4c859eSApple OSS Distributions 	int res;
284*0f4c859eSApple OSS Distributions 
285*0f4c859eSApple OSS Distributions 	assert(lock->thread == IOThreadSelf());
286*0f4c859eSApple OSS Distributions 
287*0f4c859eSApple OSS Distributions 	lock->count = 0;
288*0f4c859eSApple OSS Distributions 	lock->thread = NULL;
289*0f4c859eSApple OSS Distributions 	res = lck_mtx_sleep_deadline(&lock->mutex, LCK_SLEEP_PROMOTED_PRI, (event_t) event,
290*0f4c859eSApple OSS Distributions 	    (wait_interrupt_t) interType, __OSAbsoluteTime(deadline));
291*0f4c859eSApple OSS Distributions 
292*0f4c859eSApple OSS Distributions 	// Must re-establish the recursive lock no matter why we woke up
293*0f4c859eSApple OSS Distributions 	// otherwise we would potentially leave the return path corrupted.
294*0f4c859eSApple OSS Distributions 	assert(lock->thread == NULL);
295*0f4c859eSApple OSS Distributions 	assert(lock->count == 0);
296*0f4c859eSApple OSS Distributions 	lock->thread = IOThreadSelf();
297*0f4c859eSApple OSS Distributions 	lock->count = count;
298*0f4c859eSApple OSS Distributions 	return res;
299*0f4c859eSApple OSS Distributions }
300*0f4c859eSApple OSS Distributions 
301*0f4c859eSApple OSS Distributions void
IORecursiveLockWakeup(IORecursiveLock *,void * event,bool oneThread)302*0f4c859eSApple OSS Distributions IORecursiveLockWakeup(IORecursiveLock *, void *event, bool oneThread)
303*0f4c859eSApple OSS Distributions {
304*0f4c859eSApple OSS Distributions 	thread_wakeup_prim((event_t) event, oneThread, THREAD_AWAKENED);
305*0f4c859eSApple OSS Distributions }
306*0f4c859eSApple OSS Distributions 
307*0f4c859eSApple OSS Distributions /*
308*0f4c859eSApple OSS Distributions  * Complex (read/write) lock operations
309*0f4c859eSApple OSS Distributions  */
310*0f4c859eSApple OSS Distributions 
311*0f4c859eSApple OSS Distributions IORWLock *
IORWLockAlloc(void)312*0f4c859eSApple OSS Distributions IORWLockAlloc( void )
313*0f4c859eSApple OSS Distributions {
314*0f4c859eSApple OSS Distributions 	return lck_rw_alloc_init(IOLockGroup, LCK_ATTR_NULL);
315*0f4c859eSApple OSS Distributions }
316*0f4c859eSApple OSS Distributions 
317*0f4c859eSApple OSS Distributions void
IORWLockInlineInit(IORWLock * lock)318*0f4c859eSApple OSS Distributions IORWLockInlineInit( IORWLock *lock )
319*0f4c859eSApple OSS Distributions {
320*0f4c859eSApple OSS Distributions 	lck_rw_init(lock, IOLockGroup, LCK_ATTR_NULL);
321*0f4c859eSApple OSS Distributions }
322*0f4c859eSApple OSS Distributions 
323*0f4c859eSApple OSS Distributions void
IORWLockInlineDestroy(IORWLock * lock)324*0f4c859eSApple OSS Distributions IORWLockInlineDestroy( IORWLock * lock)
325*0f4c859eSApple OSS Distributions {
326*0f4c859eSApple OSS Distributions 	lck_rw_destroy( lock, IOLockGroup);
327*0f4c859eSApple OSS Distributions }
328*0f4c859eSApple OSS Distributions 
329*0f4c859eSApple OSS Distributions void
IORWLockFree(IORWLock * lock)330*0f4c859eSApple OSS Distributions IORWLockFree( IORWLock * lock)
331*0f4c859eSApple OSS Distributions {
332*0f4c859eSApple OSS Distributions 	lck_rw_free( lock, IOLockGroup);
333*0f4c859eSApple OSS Distributions }
334*0f4c859eSApple OSS Distributions 
335*0f4c859eSApple OSS Distributions lck_rw_t *
IORWLockGetMachLock(IORWLock * lock)336*0f4c859eSApple OSS Distributions IORWLockGetMachLock( IORWLock * lock)
337*0f4c859eSApple OSS Distributions {
338*0f4c859eSApple OSS Distributions 	return (lck_rw_t *)lock;
339*0f4c859eSApple OSS Distributions }
340*0f4c859eSApple OSS Distributions 
341*0f4c859eSApple OSS Distributions 
342*0f4c859eSApple OSS Distributions /*
343*0f4c859eSApple OSS Distributions  * Spin locks
344*0f4c859eSApple OSS Distributions  */
345*0f4c859eSApple OSS Distributions 
346*0f4c859eSApple OSS Distributions IOSimpleLock *
IOSimpleLockAlloc(void)347*0f4c859eSApple OSS Distributions IOSimpleLockAlloc( void )
348*0f4c859eSApple OSS Distributions {
349*0f4c859eSApple OSS Distributions 	return lck_spin_alloc_init( IOLockGroup, LCK_ATTR_NULL);
350*0f4c859eSApple OSS Distributions }
351*0f4c859eSApple OSS Distributions 
352*0f4c859eSApple OSS Distributions void
IOSimpleLockInit(IOSimpleLock * lock)353*0f4c859eSApple OSS Distributions IOSimpleLockInit( IOSimpleLock * lock)
354*0f4c859eSApple OSS Distributions {
355*0f4c859eSApple OSS Distributions 	lck_spin_init( lock, IOLockGroup, LCK_ATTR_NULL);
356*0f4c859eSApple OSS Distributions }
357*0f4c859eSApple OSS Distributions 
358*0f4c859eSApple OSS Distributions void
IOSimpleLockDestroy(IOSimpleLock * lock)359*0f4c859eSApple OSS Distributions IOSimpleLockDestroy( IOSimpleLock * lock )
360*0f4c859eSApple OSS Distributions {
361*0f4c859eSApple OSS Distributions 	lck_spin_destroy(lock, IOLockGroup);
362*0f4c859eSApple OSS Distributions }
363*0f4c859eSApple OSS Distributions 
364*0f4c859eSApple OSS Distributions void
IOSimpleLockFree(IOSimpleLock * lock)365*0f4c859eSApple OSS Distributions IOSimpleLockFree( IOSimpleLock * lock )
366*0f4c859eSApple OSS Distributions {
367*0f4c859eSApple OSS Distributions 	lck_spin_free( lock, IOLockGroup);
368*0f4c859eSApple OSS Distributions }
369*0f4c859eSApple OSS Distributions 
370*0f4c859eSApple OSS Distributions lck_spin_t *
IOSimpleLockGetMachLock(IOSimpleLock * lock)371*0f4c859eSApple OSS Distributions IOSimpleLockGetMachLock( IOSimpleLock * lock)
372*0f4c859eSApple OSS Distributions {
373*0f4c859eSApple OSS Distributions 	return (lck_spin_t *)lock;
374*0f4c859eSApple OSS Distributions }
375*0f4c859eSApple OSS Distributions 
376*0f4c859eSApple OSS Distributions #ifndef IOLOCKS_INLINE
377*0f4c859eSApple OSS Distributions /*
378*0f4c859eSApple OSS Distributions  * Lock assertions
379*0f4c859eSApple OSS Distributions  */
380*0f4c859eSApple OSS Distributions 
381*0f4c859eSApple OSS Distributions void
IOLockAssert(IOLock * lock,IOLockAssertState type)382*0f4c859eSApple OSS Distributions IOLockAssert(IOLock * lock, IOLockAssertState type)
383*0f4c859eSApple OSS Distributions {
384*0f4c859eSApple OSS Distributions 	LCK_MTX_ASSERT(lock, type);
385*0f4c859eSApple OSS Distributions }
386*0f4c859eSApple OSS Distributions 
387*0f4c859eSApple OSS Distributions void
IORWLockAssert(IORWLock * lock,IORWLockAssertState type)388*0f4c859eSApple OSS Distributions IORWLockAssert(IORWLock * lock, IORWLockAssertState type)
389*0f4c859eSApple OSS Distributions {
390*0f4c859eSApple OSS Distributions 	LCK_RW_ASSERT(lock, type);
391*0f4c859eSApple OSS Distributions }
392*0f4c859eSApple OSS Distributions 
393*0f4c859eSApple OSS Distributions void
IOSimpleLockAssert(IOSimpleLock * lock,IOSimpleLockAssertState type)394*0f4c859eSApple OSS Distributions IOSimpleLockAssert(IOSimpleLock *lock, IOSimpleLockAssertState type)
395*0f4c859eSApple OSS Distributions {
396*0f4c859eSApple OSS Distributions 	LCK_SPIN_ASSERT(l, type);
397*0f4c859eSApple OSS Distributions }
398*0f4c859eSApple OSS Distributions #endif /* !IOLOCKS_INLINE */
399*0f4c859eSApple OSS Distributions } /* extern "C" */
400