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