MUTEX(9) BSD Kernel Developer's Manual MUTEX(9)
mutex, mtx_init, mtx_enter, mtx_enter_try, mtx_leave,
MUTEX_ASSERT_LOCKED, MUTEX_ASSERT_UNLOCKED, MUTEX_INITIALIZER -- inter-
face to CPU mutexes
mtx_init(struct mutex *mtxp, int wantipl);
mtx_enter(struct mutex *mtxp);
mtx_enter_try(struct mutex *mtxp);
mtx_leave(struct mutex *mtxp);
MUTEX_ASSERT_LOCKED(struct mutex *mtxp);
MUTEX_ASSERT_UNLOCKED(struct mutex *mtxp);
The mutex set of functions provides a non-recursive, interrupt-aware
spinning mechanism to ensure mutual exclusion between different CPUs.
The mtx_init() function is used to initiate the mutex pointed to by mtxp.
When acquired, the mutex will cause the processor interrupt level to be
raised to wantipl if necessary.
The mtx_enter() function acquires a mutex, spinning if necessary.
The mtx_enter_try() function attempts to acquire a mutex.
The mtx_leave() function releases a mutex. In case the acquisition of
the mutex caused the interrupt level to be changed, it is then restored.
The MUTEX_ASSERT_LOCKED() and MUTEX_ASSERT_UNLOCKED() macros may be used
to assert that a mutex is held locked or unlocked by the current CPU.
A mutex declaration may be initialised with the MUTEX_INITIALIZER()
macro. When acquired, the mutex will cause the processor interrupt level
to be raised to wantipl if necessary.
mtx_init() can be called during autoconf, from process context, or from
mtx_enter(), mtx_enter_try(), and mtx_leave() can be called during auto-
conf, from process context, or from any interrupt context at or below the
interrupt level mtxp was initialised with.
The mtx_enter_try() function will return non-zero if it succeeds in
acquiring the mutex mtxp, otherwise it will return 0.
lockmgr(9), msleep(9), rwlock(9), spl(9)
The mutex functions first appeared in OpenBSD 3.6.
The mutex functions were written by Artur Grabowski <firstname.lastname@example.org>.
As these are spinning locks, don't sleep while holding one.
Multiple mutexes may be nested, but not interleaved. This is okay:
While this is not:
BSD February 13, 2014 BSD