#include <IOKit/IOLocks.h>
IOKit/IOLocks.h
variableIOLockGroup
@var IOLockGroup
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.
extern lck_grp_t *IOLockGroup
typedefIOLock
typedef struct _IOLock IOLock
functionIOLockAlloc
IOLock * IOLockAlloc(void)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Allocates and initializes a mutex in general purpose memory (lck_mtx_alloc_init). IOLock is a Mach mutex (lck_mtx_t): a general purpose blocking mutual exclusion lock from libkern/locks.h. All IOKit locks use the global lock group IOLockGroup; to simplify kext debugging and lock-heat analysis, consider lck_* locks with a per-driver lock group instead. May block, and so must not be called from interrupt level or while a spin lock is held. Returns a pointer to the allocated lock, or zero on failure.
functionIOLockFree
void IOLockFree(IOLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Frees a mutex allocated with IOLockAlloc (lck_mtx_free). The mutex should be unlocked with no waiters.
functionIOLockGetMachLock
lck_mtx_t * IOLockGetMachLock(IOLock * lock)
functionIOLockLock
void IOLockLock(IOLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Locks the mutex (lck_mtx_lock). If the lock is held by any thread, blocks waiting for its unlock; may block, and so must not be called from interrupt level or while a spin lock is held. Locking the mutex recursively from one thread results in deadlock.
functionIOLockTryLock
boolean_t IOLockTryLock(IOLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Attempts to lock the mutex without blocking (lck_mtx_try_lock). Returns true if the mutex was unlocked and is now locked by the caller, false if it is held by any thread.
functionIOLockUnlock
void IOLockUnlock(IOLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Unlocks the mutex and wakes any blocked waiters (lck_mtx_unlock). Results are undefined if the caller has not locked the mutex.
functionIOLockSleep
int IOLockSleep(IOLock * lock, void *event, UInt32 interType)
@function IOLockSleep
@abstract Sleep with mutex unlock and relock
@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.
@param lock Pointer to the locked lock.
@param event The event to sleep on. Must be non-NULL.
@param interType How can the sleep be interrupted.
@result The wait-result value indicating how the thread was awakened.
functionIOLockSleepDeadline
int IOLockSleepDeadline( IOLock * lock, void *event, AbsoluteTime deadline, UInt32 interType )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Sleeps until the specified event is signaled or the AbsoluteTime deadline passes, unlocking the mutex while asleep and reacquiring it before returning (lck_mtx_sleep_deadline with LCK_SLEEP_PROMOTED_PRI). The wakeup channel is the event pointer, which a waker passes to IOLockWakeup. interType is a wait_interrupt_t (THREAD_UNINT, THREAD_INTERRUPTIBLE, THREAD_ABORTSAFE) controlling whether the sleep can be interrupted. The caller must hold the mutex; event must be non-NULL. Returns the wait result (THREAD_AWAKENED, THREAD_TIMED_OUT, THREAD_INTERRUPTED, ...). On x86_64, kexts built against pre-Darwin 14 headers bind to a legacy variant that substitutes a synthetic event for NULL.
functionIOLockWakeup
void IOLockWakeup(IOLock * lock, void *event, bool oneThread)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Wakes threads sleeping on the specified event via IOLockSleep or IOLockSleepDeadline (thread_wakeup_prim with THREAD_AWAKENED). If oneThread is true only one waiter is awakened, otherwise all are. The wakeup channel is the event pointer alone; the lock argument is not used.
enumIOLockState
| kIOLockStateUnlocked | 0 | |
| kIOLockStateLocked | 1 |
typedefIOLockState
typedef enum IOLockState IOLockState;
functionIOLockInitWithState
void IOLockInitWithState(IOLock * lock, IOLockState state)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Deprecated (__APPLE_API_OBSOLETE). If state is kIOLockStateLocked, acquires the already-initialized mutex with lck_mtx_lock; with kIOLockStateUnlocked (as the IOLockInit macro passes) it does nothing. It does not initialize the lock storage.
macroIOLockInit
#define IOLockInit(l) IOLockInitWithState( l, kIOLockStateUnlocked);
functionIOTakeLock
static __inline__ void IOTakeLock(IOLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Deprecated. Equivalent to IOLockLock: locks the mutex, blocking if it is held.
functionIOTryLock
static __inline__ boolean_t IOTryLock(IOLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Deprecated. Equivalent to IOLockTryLock: attempts to lock the mutex without blocking, returning true on success.
functionIOUnlock
static __inline__ void IOUnlock(IOLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Deprecated. Equivalent to IOLockUnlock: unlocks the mutex.
typedefIORecursiveLock
typedef struct _IORecursiveLock IORecursiveLock
functionIORecursiveLockAlloc
IORecursiveLock * IORecursiveLockAlloc(void)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Allocates and initializes a recursive lock in general purpose memory. An IORecursiveLock wraps a Mach mutex (lck_mtx_t) with an owning-thread pointer and a recursion count: it functions identically to a mutex but allows one thread to lock more than once, with balanced unlocks. Uses the global IOLockGroup lock group (IORecursiveLockAllocWithLockGroup allows a private group). May block. Returns a pointer to the allocated lock, or zero on failure.
functionIORecursiveLockFree
void IORecursiveLockFree(IORecursiveLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Frees a lock allocated with IORecursiveLockAlloc (lck_mtx_destroy plus freeing the wrapper). The lock should be unlocked with no waiters.
functionIORecursiveLockGetMachLock
lck_mtx_t * IORecursiveLockGetMachLock(IORecursiveLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Returns the underlying Mach mutex (lck_mtx_t) embedded in an IORecursiveLock. Operating on it directly bypasses the recursion bookkeeping.
functionIORecursiveLockLock
void IORecursiveLockLock(IORecursiveLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Locks a recursive lock. If the calling thread already owns the lock the recursion count is incremented; otherwise the underlying mutex is acquired with lck_mtx_lock and ownership recorded. Blocks if the lock is held by another thread, and so must not be called from interrupt level or while a spin lock is held. Each call must be balanced with IORecursiveLockUnlock.
functionIORecursiveLockTryLock
boolean_t IORecursiveLockTryLock(IORecursiveLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Attempts to lock a recursive lock without blocking. Returns true if the lock was unlocked (lck_mtx_try_lock succeeds) or is already held by the calling thread, in which case the recursion count is incremented; returns false if it is held by another thread. Successful calls must be balanced with IORecursiveLockUnlock.
functionIORecursiveLockUnlock
void IORecursiveLockUnlock(IORecursiveLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Undoes one call to IORecursiveLockLock or a successful IORecursiveLockTryLock. When the recursion count reaches zero, ownership is cleared and the underlying mutex released (lck_mtx_unlock), waking any blocked waiters. Asserts that the calling thread owns the lock; unbalanced calls have undefined results.
functionIORecursiveLockHaveLock
boolean_t IORecursiveLockHaveLock(const IORecursiveLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Returns true if the recursive lock is held by the calling thread, false if it is unlocked or held by another thread.
functionIORecursiveLockSleep
extern int IORecursiveLockSleep(IORecursiveLock *_lock, void *event, UInt32 interType)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Sleeps on the specified event with a recursive lock held: saves and clears the recursion state, sleeps via lck_mtx_sleep (LCK_SLEEP_PROMOTED_PRI) releasing the underlying mutex, then on wakeup reacquires the mutex and restores the saved ownership and recursion count regardless of why the thread woke. The wakeup channel is the event pointer, matched by IORecursiveLockWakeup. interType is a wait_interrupt_t (THREAD_UNINT, THREAD_INTERRUPTIBLE, THREAD_ABORTSAFE). The caller must own the lock (asserted). Returns the wait result (THREAD_AWAKENED, THREAD_INTERRUPTED, ...).
functionIORecursiveLockSleepDeadline
extern int IORecursiveLockSleepDeadline( IORecursiveLock * _lock, void *event, AbsoluteTime deadline, UInt32 interType )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
As IORecursiveLockSleep, but the sleep also ends when the AbsoluteTime deadline passes (lck_mtx_sleep_deadline with LCK_SLEEP_PROMOTED_PRI); THREAD_TIMED_OUT is returned in that case. The recursion state is saved across the sleep and restored on wakeup. The caller must own the lock.
functionIORecursiveLockWakeup
extern void IORecursiveLockWakeup(IORecursiveLock *_lock, void *event, bool oneThread)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Wakes threads sleeping on the specified event via IORecursiveLockSleep or IORecursiveLockSleepDeadline (thread_wakeup_prim with THREAD_AWAKENED). If oneThread is true only one waiter is awakened, otherwise all are. The wakeup channel is the event pointer alone; the lock argument is not used.
typedefIORWLock
typedef struct _IORWLock IORWLock
functionIORWLockAlloc
IORWLock * IORWLockAlloc(void)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Allocates and initializes a read/write lock in general purpose memory (lck_rw_alloc_init). IORWLock is a Mach reader/writer lock (lck_rw_t) from libkern/locks.h, providing multiple readers or one exclusive writer. Uses the global IOLockGroup lock group; consider lck_* locks with a per-driver group for lock-heat analysis. May block, and so must not be called from interrupt level or while a spin lock is held. Returns a pointer to the allocated lock, or zero on failure.
functionIORWLockFree
void IORWLockFree(IORWLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Frees a lock allocated with IORWLockAlloc (lck_rw_free). The lock should be unlocked with no waiters.
functionIORWLockGetMachLock
lck_rw_t * IORWLockGetMachLock(IORWLock * lock)
functionIORWLockRead
void IORWLockRead(IORWLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Locks the lock for read (lck_rw_lock_shared), allowing multiple readers when there are no writers. Blocks if the lock is held for write; may block, and so must 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. Release with IORWLockUnlock.
functionIORWLockTryRead
void IORWLockTryRead(IORWLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Attempts to lock the lock for read without blocking (lck_rw_try_lock_shared). Fails, returning false, if the lock is held for write, and returns true otherwise. (The non-inline SDK prototype declares a void result; the inline form returns the lck_rw_try_lock_shared result.)
functionIORWLockWrite
void IORWLockWrite(IORWLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Locks the lock for write (lck_rw_lock_exclusive), giving one writer exclusive access. Blocks if the lock is held for read or write; may block, and so must 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. Release with IORWLockUnlock.
functionIORWLockTryWrite
void IORWLockTryWrite(IORWLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Attempts to lock the lock for write without blocking (lck_rw_try_lock_exclusive). Fails, returning false, if the lock is held for read or write, and returns true otherwise. (The non-inline SDK prototype declares a void result; the inline form returns the lck_rw_try_lock_exclusive result.)
functionIORWLockUnlock
void IORWLockUnlock(IORWLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Undoes one call to IORWLockRead or IORWLockWrite (lck_rw_done releases whichever hold the caller has). Results are undefined if the caller has not locked the lock. May block waking waiters, and so must not be called from interrupt level or while a spin lock is held.
functionIOReadLock
static __inline__ void IOReadLock(IORWLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Deprecated. Equivalent to IORWLockRead: locks the read/write lock for read.
functionIOWriteLock
static __inline__ void IOWriteLock(IORWLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Deprecated. Equivalent to IORWLockWrite: locks the read/write lock for write.
functionIORWUnlock
static __inline__ void IORWUnlock(IORWLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Deprecated. Equivalent to IORWLockUnlock: releases one read or write hold on the lock.
typedefIOSimpleLock
typedef struct _IOSimpleLock IOSimpleLock
functionIOSimpleLockAlloc
IOSimpleLock * IOSimpleLockAlloc(void)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Allocates and initializes a spin lock in general purpose memory (lck_spin_alloc_init). IOSimpleLock is a Mach spin lock (lck_spin_t) from libkern/locks.h, providing non-blocking mutual exclusion between thread context and interrupt context, or for multiprocessor synchronization. Uses the global IOLockGroup lock group. The allocation itself may block, and so must not be done from interrupt level or while a spin lock is held. Returns a pointer to the allocated lock, or zero on failure.
functionIOSimpleLockFree
void IOSimpleLockFree(IOSimpleLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Frees a spin lock allocated with IOSimpleLockAlloc (lck_spin_free).
functionIOSimpleLockGetMachLock
lck_spin_t * IOSimpleLockGetMachLock(IOSimpleLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Returns the underlying Mach spin lock (lck_spin_t) of an IOSimpleLock, for use with the lck_spin_* API. An IOSimpleLock is the lck_spin_t itself.
functionIOSimpleLockInit
void IOSimpleLockInit(IOSimpleLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Initializes a spin lock that was not heap allocated, e.g. one embedded as a member variable, to the unlocked state (lck_spin_init with IOLockGroup). Balance with IOSimpleLockDestroy when finished to avoid lock group refcount leaks.
functionIOSimpleLockDestroy
void IOSimpleLockDestroy(IOSimpleLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
De-initializes a spin lock initialized with IOSimpleLockInit (lck_spin_destroy), releasing system resources such as lock group refcounts.
functionIOSimpleLockLock
void IOSimpleLockLock(IOSimpleLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Locks the spin lock (lck_spin_lock); if it is held, spins waiting for its unlock. Spin locks disable preemption, cannot be held across any blocking operation, and should be held only for very short periods. When used to synchronize between interrupt context and thread context they should be taken with interrupts disabled - IOSimpleLockLockDisableInterrupt does both. Locking recursively from one thread results in deadlock.
functionIOSimpleLockTryLock
boolean_t IOSimpleLockTryLock(IOSimpleLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Attempts to lock the spin lock without spinning (lck_spin_try_lock). Returns true if the lock was unlocked and is now locked by the caller, false if it is held. Successful calls should be balanced with IOSimpleLockUnlock.
functionIOSimpleLockUnlock
void IOSimpleLockUnlock(IOSimpleLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Unlocks the spin lock and restores preemption (lck_spin_unlock). Results are undefined if the caller has not locked the lock.
typedefIOInterruptState
typedef boolean_t IOInterruptState
functionIOSimpleLockLockDisableInterrupt
static __inline__ IOInterruptState IOSimpleLockLockDisableInterrupt(IOSimpleLock * lock)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Disables interrupts (ml_set_interrupts_enabled(false)) and then locks the spin lock, spinning if it is held. This is the form to use when a lock synchronizes thread context with interrupt context. Returns the previous interrupt state, to be passed to IOSimpleLockUnlockEnableInterrupt.
functionIOSimpleLockUnlockEnableInterrupt
static __inline__ void IOSimpleLockUnlockEnableInterrupt( IOSimpleLock * lock, IOInterruptState state )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu iokit/Kernel/IOLocks.cpp, iokit/IOKit/IOLocks.h
Unlocks the spin lock, restoring preemption, then restores the interrupt enable state returned by IOSimpleLockLockDisableInterrupt. Results are undefined if the caller has not locked the lock.