MUTEX(9)                     OpenBSD Kernel Manual                    MUTEX(9)

NAME
     mutex, mtx_init, mtx_enter, mtx_leave - interface to CPU mutexes

SYNOPSIS
     #include <sys/mutex.h>

     void
     mtx_init(struct mutex *mtxp, int wantipl);

     void
     mtx_enter(struct mutex *mtxp);

     void
     mtx_leave(struct mutex *mtxp);

DESCRIPTION
     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
     changed to wantipl.

     The mtx_enter() function acquires a mutex, spinning if necessary.

     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.

SEE ALSO
     lockmgr(9), spl(9)

HISTORY
     The mutex functions first appeared in OpenBSD 3.6.

AUTHORS
     The mutex functions were written by Artur Grabowski <art@openbsd.org>.

CAVEATS
     Multiple mutexes may be nested, but not interleaved.  This is okay:

           mtx_enter(foo);
           mtx_enter(bar);
           mtx_leave(bar);
           mtx_leave(foo);

     While this is not:

           mtx_enter(foo);
           mtx_enter(bar);
           mtx_leave(foo);
           mtx_leave(bar);

OpenBSD 4.1                    February 9, 2005                              1
