#include <kern/lock_mtx.h>

kern/lock_mtx.h Kernel.framework

10 functions · 7 macros

macrodecl_lck_mtx_data

#define decl_lck_mtx_data(class, name) class lck_mtx_t name

functionlck_mtx_alloc_init

extern lck_mtx_t *lck_mtx_alloc_init(lck_grp_t *grp, lck_attr_t *attr)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/lock_mtx.c
Allocates a mutex and initializes it in the manner of lck_mtx_init with the given group and attributes. The result is freed with lck_mtx_free.

functionlck_mtx_init

extern void lck_mtx_init(lck_mtx_t *lck, lck_grp_t *grp, lck_attr_t *attr)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/lock_mtx.c
Initializes a mutex, associating it with the given lock group and taking a reference on the group. A NULL attribute selects the defaults; LCK_ATTR_DEBUG in the attributes enables profiling for the lock. Mutexes are blocking locks with adaptive spin and priority inheritance; a destroyed or waited-on mutex must be re-initialized before reuse.

functionlck_mtx_lock

extern void lck_mtx_lock(lck_mtx_t *lck)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/lock_mtx.c
Locks the mutex for the current thread, blocking (after an adaptive spin) if it is owned by another thread. Contended acquisitions use turnstiles, propagating the waiters' priority to the owner. Must not be called from interrupt context; recursive acquisition by the owner is a deadlock/panic.

functionlck_mtx_unlock

extern void lck_mtx_unlock(lck_mtx_t *lck)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/lock_mtx.c
Unlocks the mutex, waking or handing the lock to a waiting thread and undoing any priority inheritance. Must be called by the owning thread.

functionlck_mtx_destroy

extern void lck_mtx_destroy(lck_mtx_t *lck, lck_grp_t *grp)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/lock_mtx.c
Destroys a mutex initialized with lck_mtx_init, marking it unusable (LCK_MTX_TAG_DESTROYED) and dropping its reference on the lock group. Panics if the mutex still has waiters or is in an invalid state. Does not free the memory; for mutexes obtained from lck_mtx_alloc_init use lck_mtx_free.

functionlck_mtx_free

extern void lck_mtx_free(lck_mtx_t *lck, lck_grp_t *grp)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/lock_mtx.c
Destroys a mutex allocated by lck_mtx_alloc_init and frees its memory, dropping the reference on the lock group.

functionlck_mtx_sleep

extern wait_result_t lck_mtx_sleep(
	lck_mtx_t *lck,
	lck_sleep_action_t lck_sleep_action,
	event_t event,
	wait_interrupt_t interruptible
)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/locks.c
Atomically releases the mutex and waits for the specified event, in the manner of assert_wait plus thread_block; on wakeup the mutex is re-acquired unless LCK_SLEEP_UNLOCK is set. lck_sleep_action may include: LCK_SLEEP_DEFAULT release and re-acquire the lock LCK_SLEEP_UNLOCK return with the lock released LCK_SLEEP_SPIN re-acquire in spin mode LCK_SLEEP_SPIN_ALWAYS re-acquire in spin-always mode LCK_SLEEP_PROMOTED_PRI hold a priority floor for the sleeping thread Returns the wait result (THREAD_AWAKENED, THREAD_TIMED_OUT, THREAD_INTERRUPTED, ...) per the interruptible argument. Panics on invalid action bits.

functionlck_mtx_sleep_deadline

extern wait_result_t lck_mtx_sleep_deadline(
	lck_mtx_t *lck,
	lck_sleep_action_t lck_sleep_action,
	event_t event,
	wait_interrupt_t interruptible,
	uint64_t deadline
)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/locks.c
As lck_mtx_sleep, but the wait is bounded by an absolute deadline in mach_absolute_time units (via assert_wait_deadline); the wait result is THREAD_TIMED_OUT if the deadline expires before wakeup.

macroLCK_MTX_ASSERT_OWNED

#define LCK_MTX_ASSERT_OWNED LCK_ASSERT_OWNED

macroLCK_MTX_ASSERT_NOTOWNED

#define LCK_MTX_ASSERT_NOTOWNED LCK_ASSERT_NOTOWNED

functionlck_mtx_assert

extern void lck_mtx_assert(lck_mtx_t *lck, unsigned int type)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/lock_mtx.c
Asserts the ownership state of the mutex relative to the current thread: panics if type is LCK_MTX_ASSERT_OWNED and the current thread does not own the lock, or if type is LCK_MTX_ASSERT_NOTOWNED and it does. Panics on any other type value.

functionlck_mtx_assert_owned_spin

extern void lck_mtx_assert_owned_spin(lck_mtx_t *lck)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu SDK kern/lock_mtx.h; not present in available xnu source
Asserts that the current thread owns the mutex, which may be held in spin mode (as after lck_mtx_lock_spin); panics otherwise. Wrapped by the LCK_MTX_ASSERT_OWNED_SPIN macro, compiled in only under MACH_ASSERT/DEBUG kernels. Implementation not present in the available xnu sources; semantics inferred from the header and the lck_mtx_assert family.

macroLCK_MTX_ASSERT

#define LCK_MTX_ASSERT(lck, type) 

macroLCK_MTX_ASSERT_OWNED_SPIN

#define LCK_MTX_ASSERT_OWNED_SPIN(lck) 

macroLCK_MTX_ASSERT_DEBUG

#define LCK_MTX_ASSERT_DEBUG(lck, type) 

macroLCK_MTX_ASSERT_OWNED_SPIN_DEBUG

#define LCK_MTX_ASSERT_OWNED_SPIN_DEBUG(lck)