]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/IOLocks.h
xnu-4903.270.47.tar.gz
[apple/xnu.git] / iokit / IOKit / IOLocks.h
CommitLineData
1c79356b 1/*
39236c6e 2 * Copyright (c) 1998-2012 Apple Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 *
30 */
31
32#ifndef __IOKIT_IOLOCKS_H
33#define __IOKIT_IOLOCKS_H
34
35#ifndef KERNEL
36#error IOLocks.h is for kernel use only
37#endif
38
9bccf70c 39#include <sys/appleapiopts.h>
fe8ab488 40#include <sys/cdefs.h>
1c79356b
A
41
42#include <IOKit/system.h>
43
44#include <IOKit/IOReturn.h>
45#include <IOKit/IOTypes.h>
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
91447636 51#include <libkern/locks.h>
1c79356b
A
52#include <machine/machine_routines.h>
53
b0d623f7 54/*! @var IOLockGroup
0a7de745
A
55 * Global lock group used by all IOKit locks. To simplify kext debugging and lock-heat analysis, consider using lck_* locks with a per-driver lock group, as defined in kern/locks.h.
56 */
57extern lck_grp_t *IOLockGroup;
91447636 58
b0d623f7 59#if defined(XNU_KERNEL_PRIVATE)
0a7de745 60#define IOLOCKS_INLINE 1
b0d623f7
A
61#endif
62
1c79356b
A
63/*
64 * Mutex lock operations
65 */
66
0a7de745
A
67#ifdef IOLOCKS_INLINE
68typedef lck_mtx_t IOLock;
91447636 69#else
0a7de745
A
70typedef struct _IOLock IOLock;
71#endif /* IOLOCKS_INLINE */
91447636 72
1c79356b
A
73
74/*! @function IOLockAlloc
0a7de745
A
75 * @abstract Allocates and initializes a mutex.
76 * @discussion Allocates a mutex in general purpose memory, and initializes it. Mutexes are general purpose blocking mutual exclusion locks, supplied by libkern/locks.h. This function may block and so should not be called from interrupt level or while a spin lock is held. IOLocks use the global IOKit lock group, IOLockGroup. To simplify kext debugging and lock-heat analysis, consider using lck_* locks with a per-driver lock group, as defined in kern/locks.h.
77 * @result Pointer to the allocated lock, or zero on failure. */
1c79356b
A
78
79IOLock * IOLockAlloc( void );
80
81/*! @function IOLockFree
0a7de745
A
82 * @abstract Frees a mutex.
83 * @discussion Frees a lock allocated with IOLockAlloc. Mutex should be unlocked with no waiters.
84 * @param lock Pointer to the allocated lock. */
1c79356b 85
0a7de745 86void IOLockFree( IOLock * lock);
1c79356b 87
91447636 88/*! @function IOLockGetMachLock
0a7de745
A
89 * @abstract Accessor to a Mach mutex.
90 * @discussion Accessor to the Mach mutex.
91 * @param lock Pointer to the allocated lock. */
91447636
A
92
93lck_mtx_t * IOLockGetMachLock( IOLock * lock);
94
1c79356b 95/*! @function IOLockLock
0a7de745
A
96 * @abstract Lock a mutex.
97 * @discussion Lock the mutex. If the lock is held by any thread, block waiting for its unlock. This function may block and so should not be called from interrupt level or while a spin lock is held. Locking the mutex recursively from one thread will result in deadlock.
98 * @param lock Pointer to the allocated lock. */
1c79356b 99
0a7de745
A
100#ifdef IOLOCKS_INLINE
101#define IOLockLock(l) lck_mtx_lock(l)
91447636 102#else
0a7de745
A
103void IOLockLock( IOLock * lock);
104#endif /* !IOLOCKS_INLINE */
1c79356b
A
105
106/*! @function IOLockTryLock
0a7de745
A
107 * @abstract Attempt to lock a mutex.
108 * @discussion Lock the mutex if it is currently unlocked, and return true. If the lock is held by any thread, return false.
109 * @param lock Pointer to the allocated lock.
110 * @result True if the mutex was unlocked and is now locked by the caller, otherwise false. */
1c79356b 111
0a7de745
A
112#ifdef IOLOCKS_INLINE
113#define IOLockTryLock(l) lck_mtx_try_lock(l)
91447636
A
114#else
115boolean_t IOLockTryLock( IOLock * lock);
0a7de745 116#endif /* !IOLOCKS_INLINE */
1c79356b
A
117
118/*! @function IOLockUnlock
0a7de745
A
119 * @abstract Unlock a mutex.
120 * @discussion Unlock the mutex and wake any blocked waiters. Results are undefined if the caller has not locked the mutex. This function may block and so should not be called from interrupt level or while a spin lock is held.
121 * @param lock Pointer to the allocated lock. */
1c79356b 122
0a7de745
A
123#ifdef IOLOCKS_INLINE
124#define IOLockUnlock(l) lck_mtx_unlock(l)
91447636 125#else
0a7de745
A
126void IOLockUnlock( IOLock * lock);
127#endif /* !IOLOCKS_INLINE */
1c79356b 128
9bccf70c 129/*! @function IOLockSleep
0a7de745
A
130 * @abstract Sleep with mutex unlock and relock
131 * @discussion Prepare to sleep,unlock the mutex, and re-acquire it on wakeup. Results are undefined if the caller has not locked the mutex. This function may block and so should not be called from interrupt level or while a spin lock is held.
132 * @param lock Pointer to the locked lock.
133 * @param event The event to sleep on. Must be non-NULL.
134 * @param interType How can the sleep be interrupted.
135 * @result The wait-result value indicating how the thread was awakened.*/
136int IOLockSleep( IOLock * lock, void *event, UInt32 interType) __DARWIN14_ALIAS(IOLockSleep);
9bccf70c 137
0a7de745
A
138int IOLockSleepDeadline( IOLock * lock, void *event,
139 AbsoluteTime deadline, UInt32 interType) __DARWIN14_ALIAS(IOLockSleepDeadline);
9bccf70c 140
0a7de745 141void IOLockWakeup(IOLock * lock, void *event, bool oneThread) __DARWIN14_ALIAS(IOLockWakeup);
9bccf70c 142
5c9f4661
A
143#ifdef XNU_KERNEL_PRIVATE
144/*! @enum IOLockAssertState
145 * @abstract Used with IOLockAssert to assert the state of a lock.
146 */
147typedef enum {
0a7de745
A
148 kIOLockAssertOwned = LCK_ASSERT_OWNED,
149 kIOLockAssertNotOwned = LCK_ASSERT_NOTOWNED
5c9f4661
A
150} IOLockAssertState;
151
152#ifdef IOLOCKS_INLINE
153#define IOLockAssert(l, type) LCK_MTX_ASSERT(l, type)
154#else
155/*! @function IOLockAssert
156 * @abstract Assert that lock is either held or not held by current thread.
157 * @discussion Call with either kIOLockAssertOwned or kIOLockAssertNotOwned.
158 * Panics the kernel if the lock is not owned if called with kIOLockAssertOwned,
159 * and vice-versa.
160 */
0a7de745 161void IOLockAssert(IOLock * lock, IOLockAssertState type);
5c9f4661
A
162#endif /* !IOLOCKS_INLINE */
163#endif /* !XNU_KERNEL_PRIVATE */
164
9bccf70c 165#ifdef __APPLE_API_OBSOLETE
1c79356b
A
166
167/* The following API is deprecated */
168
169typedef enum {
0a7de745
A
170 kIOLockStateUnlocked = 0,
171 kIOLockStateLocked = 1
1c79356b
A
172} IOLockState;
173
0a7de745
A
174void IOLockInitWithState( IOLock * lock, IOLockState state);
175#define IOLockInit( l ) IOLockInitWithState( l, kIOLockStateUnlocked);
1c79356b 176
0a7de745
A
177static __inline__ void
178IOTakeLock( IOLock * lock)
179{
180 IOLockLock(lock);
181}
182static __inline__ boolean_t
183IOTryLock( IOLock * lock)
184{
185 return IOLockTryLock(lock);
186}
187static __inline__ void
188IOUnlock( IOLock * lock)
189{
190 IOLockUnlock(lock);
191}
1c79356b 192
9bccf70c 193#endif /* __APPLE_API_OBSOLETE */
1c79356b
A
194
195/*
196 * Recursive lock operations
197 */
198
199typedef struct _IORecursiveLock IORecursiveLock;
200
201/*! @function IORecursiveLockAlloc
0a7de745
A
202 * @abstract Allocates and initializes an recursive lock.
203 * @discussion Allocates a recursive lock in general purpose memory, and initializes it. Recursive locks function identically to mutexes but allow one thread to lock more than once, with balanced unlocks. IORecursiveLocks use the global IOKit lock group, IOLockGroup. To simplify kext debugging and lock-heat analysis, consider using lck_* locks with a per-driver lock group, as defined in kern/locks.h.
204 * @result Pointer to the allocated lock, or zero on failure. */
1c79356b
A
205
206IORecursiveLock * IORecursiveLockAlloc( void );
207
208/*! @function IORecursiveLockFree
0a7de745
A
209 * @abstract Frees a recursive lock.
210 * @discussion Frees a lock allocated with IORecursiveLockAlloc. Lock should be unlocked with no waiters.
211 * @param lock Pointer to the allocated lock. */
1c79356b 212
0a7de745 213void IORecursiveLockFree( IORecursiveLock * lock);
1c79356b 214
91447636 215/*! @function IORecursiveLockGetMachLock
0a7de745
A
216 * @abstract Accessor to a Mach mutex.
217 * @discussion Accessor to the Mach mutex.
218 * @param lock Pointer to the allocated lock. */
91447636
A
219
220lck_mtx_t * IORecursiveLockGetMachLock( IORecursiveLock * lock);
221
1c79356b 222/*! @function IORecursiveLockLock
0a7de745
A
223 * @abstract Lock a recursive lock.
224 * @discussion Lock the recursive lock. If the lock is held by another thread, block waiting for its unlock. This function may block and so should not be called from interrupt level or while a spin lock is held. The lock may be taken recursively by the same thread, with a balanced number of calls to IORecursiveLockUnlock.
225 * @param lock Pointer to the allocated lock. */
1c79356b 226
0a7de745 227void IORecursiveLockLock( IORecursiveLock * lock);
1c79356b
A
228
229/*! @function IORecursiveLockTryLock
0a7de745
A
230 * @abstract Attempt to lock a recursive lock.
231 * @discussion Lock the lock if it is currently unlocked, or held by the calling thread, and return true. If the lock is held by another thread, return false. Successful calls to IORecursiveLockTryLock should be balanced with calls to IORecursiveLockUnlock.
232 * @param lock Pointer to the allocated lock.
233 * @result True if the lock is now locked by the caller, otherwise false. */
1c79356b 234
0a7de745 235boolean_t IORecursiveLockTryLock( IORecursiveLock * lock);
1c79356b
A
236
237/*! @function IORecursiveLockUnlock
0a7de745
A
238 * @abstract Unlock a recursive lock.
239 * @discussion Undo one call to IORecursiveLockLock, if the lock is now unlocked wake any blocked waiters. Results are undefined if the caller does not balance calls to IORecursiveLockLock with IORecursiveLockUnlock. This function may block and so should not be called from interrupt level or while a spin lock is held.
240 * @param lock Pointer to the allocated lock. */
1c79356b 241
0a7de745 242void IORecursiveLockUnlock( IORecursiveLock * lock);
1c79356b
A
243
244/*! @function IORecursiveLockHaveLock
0a7de745
A
245 * @abstract Check if a recursive lock is held by the calling thread.
246 * @discussion If the lock is held by the calling thread, return true, otherwise the lock is unlocked, or held by another thread and false is returned.
247 * @param lock Pointer to the allocated lock.
248 * @result True if the calling thread holds the lock otherwise false. */
1c79356b 249
0a7de745 250boolean_t IORecursiveLockHaveLock( const IORecursiveLock * lock);
1c79356b 251
0a7de745
A
252extern int IORecursiveLockSleep( IORecursiveLock *_lock,
253 void *event, UInt32 interType);
254extern int IORecursiveLockSleepDeadline( IORecursiveLock * _lock, void *event,
255 AbsoluteTime deadline, UInt32 interType);
256extern void IORecursiveLockWakeup( IORecursiveLock *_lock,
257 void *event, bool oneThread);
1c79356b
A
258
259/*
260 * Complex (read/write) lock operations
261 */
262
0a7de745
A
263#ifdef IOLOCKS_INLINE
264typedef lck_rw_t IORWLock;
91447636 265#else
0a7de745
A
266typedef struct _IORWLock IORWLock;
267#endif /* IOLOCKS_INLINE */
1c79356b
A
268
269/*! @function IORWLockAlloc
0a7de745
A
270 * @abstract Allocates and initializes a read/write lock.
271 * @discussion Allocates and initializes a read/write lock in general purpose memory. Read/write locks provide for multiple readers, one exclusive writer, and are supplied by libkern/locks.h. This function may block and so should not be called from interrupt level or while a spin lock is held. IORWLocks use the global IOKit lock group, IOLockGroup. To simplify kext debugging and lock-heat analysis, consider using lck_* locks with a per-driver lock group, as defined in kern/locks.h.
272 * @result Pointer to the allocated lock, or zero on failure. */
1c79356b
A
273
274IORWLock * IORWLockAlloc( void );
275
276/*! @function IORWLockFree
0a7de745
A
277 * @abstract Frees a read/write lock.
278 * @discussion Frees a lock allocated with IORWLockAlloc. Lock should be unlocked with no waiters.
279 * @param lock Pointer to the allocated lock. */
1c79356b 280
0a7de745 281void IORWLockFree( IORWLock * lock);
1c79356b 282
91447636 283/*! @function IORWLockGetMachLock
0a7de745
A
284 * @abstract Accessor to a Mach read/write lock.
285 * @discussion Accessor to the Mach read/write lock.
286 * @param lock Pointer to the allocated lock. */
91447636
A
287
288lck_rw_t * IORWLockGetMachLock( IORWLock * lock);
289
1c79356b 290/*! @function IORWLockRead
0a7de745
A
291 * @abstract Lock a read/write lock for read.
292 * @discussion Lock the lock for read, allowing multiple readers when there are no writers. If the lock is held for write, block waiting for its unlock. This function may block and so should not be called from interrupt level or while a spin lock is held. Locking the lock recursively from one thread, for read or write, can result in deadlock.
293 * @param lock Pointer to the allocated lock. */
1c79356b 294
0a7de745
A
295#ifdef IOLOCKS_INLINE
296#define IORWLockRead(l) lck_rw_lock_shared(l)
91447636 297#else
0a7de745
A
298void IORWLockRead(IORWLock * lock);
299#endif /* !IOLOCKS_INLINE */
1c79356b
A
300
301/*! @function IORWLockWrite
0a7de745
A
302 * @abstract Lock a read/write lock for write.
303 * @discussion Lock the lock for write, allowing one writer exlusive access. If the lock is held for read or write, block waiting for its unlock. This function may block and so should not be called from interrupt level or while a spin lock is held. Locking the lock recursively from one thread, for read or write, can result in deadlock.
304 * @param lock Pointer to the allocated lock. */
1c79356b 305
0a7de745
A
306#ifdef IOLOCKS_INLINE
307#define IORWLockWrite(l) lck_rw_lock_exclusive(l)
91447636 308#else
0a7de745
A
309void IORWLockWrite( IORWLock * lock);
310#endif /* !IOLOCKS_INLINE */
1c79356b
A
311
312/*! @function IORWLockUnlock
0a7de745
A
313 * @abstract Unlock a read/write lock.
314 * @discussion Undo one call to IORWLockRead or IORWLockWrite. Results are undefined if the caller has not locked the lock. This function may block and so should not be called from interrupt level or while a spin lock is held.
315 * @param lock Pointer to the allocated lock. */
1c79356b 316
0a7de745
A
317#ifdef IOLOCKS_INLINE
318#define IORWLockUnlock(l) lck_rw_done(l)
91447636 319#else
0a7de745
A
320void IORWLockUnlock( IORWLock * lock);
321#endif /* !IOLOCKS_INLINE */
b0d623f7 322
5c9f4661
A
323#ifdef XNU_KERNEL_PRIVATE
324/*! @enum IORWLockAssertState
325 * @abstract Used with IORWLockAssert to assert the state of a lock.
326 */
327typedef enum {
0a7de745
A
328 kIORWLockAssertRead = LCK_RW_ASSERT_SHARED,
329 kIORWLockAssertWrite = LCK_RW_ASSERT_EXCLUSIVE,
330 kIORWLockAssertHeld = LCK_RW_ASSERT_HELD,
331 kIORWLockAssertNotHeld = LCK_RW_ASSERT_NOTHELD
5c9f4661
A
332} IORWLockAssertState;
333
334#ifdef IOLOCKS_INLINE
335#define IORWLockAssert(l, type) LCK_RW_ASSERT(l, type)
336#else
337/*! @function IORWLockAssert
338 * @abstract Assert that a reader-writer lock is either held or not held
339 * by the current thread.
340 * @discussion Call with a value defined by the IORWLockAssertState type.
341 * If the specified lock is not in the state specified by the type argument,
342 * then the kernel will panic.
343 */
0a7de745 344void IORWLockAssert(IORWLock * lock, IORWLockAssertState type);
5c9f4661
A
345#endif /* !IOLOCKS_INLINE */
346#endif /* !XNU_KERNEL_PRIVATE */
1c79356b 347
9bccf70c 348#ifdef __APPLE_API_OBSOLETE
1c79356b
A
349
350/* The following API is deprecated */
351
0a7de745
A
352static __inline__ void
353IOReadLock( IORWLock * lock)
354{
355 IORWLockRead(lock);
356}
357static __inline__ void
358IOWriteLock( IORWLock * lock)
359{
360 IORWLockWrite(lock);
361}
362static __inline__ void
363IORWUnlock( IORWLock * lock)
364{
365 IORWLockUnlock(lock);
366}
1c79356b 367
9bccf70c 368#endif /* __APPLE_API_OBSOLETE */
1c79356b
A
369
370
371/*
372 * Simple locks. Cannot block while holding a simple lock.
373 */
374
0a7de745
A
375#ifdef IOLOCKS_INLINE
376typedef lck_spin_t IOSimpleLock;
91447636 377#else
0a7de745
A
378typedef struct _IOSimpleLock IOSimpleLock;
379#endif /* IOLOCKS_INLINE */
1c79356b
A
380
381/*! @function IOSimpleLockAlloc
0a7de745
A
382 * @abstract Allocates and initializes a spin lock.
383 * @discussion Allocates and initializes a spin lock in general purpose memory. Spin locks provide non-blocking mutual exclusion for synchronization between thread context and interrupt context, or for multiprocessor synchronization, and are supplied by libkern/locks.h. This function may block and so should not be called from interrupt level or while a spin lock is held. IOSimpleLocks use the global IOKit lock group, IOLockGroup. To simplify kext debugging and lock-heat analysis, consider using lck_* locks with a per-driver lock group, as defined in kern/locks.h.
384 * @result Pointer to the allocated lock, or zero on failure. */
1c79356b
A
385
386IOSimpleLock * IOSimpleLockAlloc( void );
387
388/*! @function IOSimpleLockFree
0a7de745
A
389 * @abstract Frees a spin lock.
390 * @discussion Frees a lock allocated with IOSimpleLockAlloc.
391 * @param lock Pointer to the lock. */
1c79356b
A
392
393void IOSimpleLockFree( IOSimpleLock * lock );
394
91447636 395/*! @function IOSimpleLockGetMachLock
0a7de745
A
396 * @abstract Accessor to a Mach spin lock.
397 * @discussion Accessor to the Mach spin lock.
398 * @param lock Pointer to the allocated lock. */
91447636
A
399
400lck_spin_t * IOSimpleLockGetMachLock( IOSimpleLock * lock);
401
1c79356b 402/*! @function IOSimpleLockInit
0a7de745
A
403 * @abstract Initialize a spin lock.
404 * @discussion Initialize an embedded spin lock, to the unlocked state.
405 * @param lock Pointer to the lock. */
1c79356b
A
406
407void IOSimpleLockInit( IOSimpleLock * lock );
408
409/*! @function IOSimpleLockLock
0a7de745
A
410 * @abstract Lock a spin lock.
411 * @discussion Lock the spin lock. If the lock is held, spin waiting for its unlock. Spin locks disable preemption, cannot be held across any blocking operation, and should be held for very short periods. When used to synchronize between interrupt context and thread context they should be locked with interrupts disabled - IOSimpleLockLockDisableInterrupt() will do both. Locking the lock recursively from one thread will result in deadlock.
412 * @param lock Pointer to the lock. */
1c79356b 413
0a7de745
A
414#ifdef IOLOCKS_INLINE
415#define IOSimpleLockLock(l) lck_spin_lock(l)
91447636
A
416#else
417void IOSimpleLockLock( IOSimpleLock * lock );
0a7de745 418#endif /* !IOLOCKS_INLINE */
b0d623f7 419
1c79356b
A
420
421/*! @function IOSimpleLockTryLock
0a7de745
A
422 * @abstract Attempt to lock a spin lock.
423 * @discussion Lock the spin lock if it is currently unlocked, and return true. If the lock is held, return false. Successful calls to IOSimpleLockTryLock should be balanced with calls to IOSimpleLockUnlock.
424 * @param lock Pointer to the lock.
425 * @result True if the lock was unlocked and is now locked by the caller, otherwise false. */
1c79356b 426
0a7de745
A
427#ifdef IOLOCKS_INLINE
428#define IOSimpleLockTryLock(l) lck_spin_try_lock(l)
91447636
A
429#else
430boolean_t IOSimpleLockTryLock( IOSimpleLock * lock );
0a7de745 431#endif /* !IOLOCKS_INLINE */
1c79356b
A
432
433/*! @function IOSimpleLockUnlock
0a7de745
A
434 * @abstract Unlock a spin lock.
435 * @discussion Unlock the lock, and restore preemption. Results are undefined if the caller has not locked the lock.
436 * @param lock Pointer to the lock. */
1c79356b 437
0a7de745
A
438#ifdef IOLOCKS_INLINE
439#define IOSimpleLockUnlock(l) lck_spin_unlock(l)
91447636
A
440#else
441void IOSimpleLockUnlock( IOSimpleLock * lock );
0a7de745 442#endif /* !IOLOCKS_INLINE */
1c79356b 443
5c9f4661
A
444#ifdef XNU_KERNEL_PRIVATE
445/*! @enum IOSimpleLockAssertState
446 * @abstract Used with IOSimpleLockAssert to assert the state of a lock.
447 */
448typedef enum {
0a7de745
A
449 kIOSimpleLockAssertOwned = LCK_ASSERT_OWNED,
450 kIOSimpleLockAssertNotOwned = LCK_ASSERT_NOTOWNED
5c9f4661
A
451} IOSimpleLockAssertState;
452
453#ifdef IOLOCKS_INLINE
454#define IOSimpleLockAssert(l, type) LCK_SPIN_ASSERT(l, type)
455#else
456/*! @function IOSimpleLockAssert
457 * @abstract Assert that spinlock is either held or not held by current thread.
458 * @discussion Call with either kIOSimpleLockAssertOwned or kIOSimpleLockAssertNotOwned.
459 * Panics the kernel if the lock is not owned if called with
460 * kIOSimpleLockAssertOwned and vice-versa.
461 */
0a7de745 462void IOSimpleLockAssert(IOSimpleLock *lock, IOSimpleLockAssertState type);
5c9f4661
A
463#endif /* !IOLOCKS_INLINE */
464#endif /* !XNU_KERNEL_PRIVATE */
465
b0d623f7
A
466#if __LP64__
467typedef boolean_t IOInterruptState;
468#else
1c79356b 469typedef long int IOInterruptState;
b0d623f7 470#endif
1c79356b
A
471
472/*! @function IOSimpleLockLockDisableInterrupt
0a7de745
A
473 * @abstract Lock a spin lock.
474 * @discussion Lock the spin lock. If the lock is held, spin waiting for its unlock. Simple locks disable preemption, cannot be held across any blocking operation, and should be held for very short periods. When used to synchronize between interrupt context and thread context they should be locked with interrupts disabled - IOSimpleLockLockDisableInterrupt() will do both. Locking the lock recursively from one thread will result in deadlock.
475 * @param lock Pointer to the lock. */
1c79356b
A
476
477static __inline__
0a7de745
A
478IOInterruptState
479IOSimpleLockLockDisableInterrupt( IOSimpleLock * lock )
1c79356b 480{
0a7de745
A
481 IOInterruptState state = ml_set_interrupts_enabled( false );
482 IOSimpleLockLock( lock );
483 return state;
1c79356b
A
484}
485
486/*! @function IOSimpleLockUnlockEnableInterrupt
0a7de745
A
487 * @abstract Unlock a spin lock, and restore interrupt state.
488 * @discussion Unlock the lock, and restore preemption and interrupts to the state as they were when the lock was taken. Results are undefined if the caller has not locked the lock.
489 * @param lock Pointer to the lock.
490 * @param state The interrupt state returned by IOSimpleLockLockDisableInterrupt() */
1c79356b
A
491
492static __inline__
0a7de745
A
493void
494IOSimpleLockUnlockEnableInterrupt( IOSimpleLock * lock,
495 IOInterruptState state )
1c79356b 496{
0a7de745
A
497 IOSimpleLockUnlock( lock );
498 ml_set_interrupts_enabled( state );
1c79356b
A
499}
500
501#ifdef __cplusplus
502} /* extern "C" */
503#endif
504
505#endif /* !__IOKIT_IOLOCKS_H */