#include <kern/lock_rw.h>
kern/lock_rw.h
typedeflck_rw_t
typedef struct __lck_rw_t__ lck_rw_t
macrodecl_lck_rw_data
#define decl_lck_rw_data(class, name) class lck_rw_t name
macroLCK_RW_DEFINE_ATTR
#define LCK_RW_DEFINE_ATTR(var, grp, attr) lck_rw_t var; static __startup_data struct lck_rw_startup_spec __startup_lck_rw_spec_ ## var = { &var, grp, attr }; STARTUP_ARG(LOCKS, STARTUP_RANK_FOURTH, lck_rw_startup_init, &__startup_lck_rw_spec_ ## var)
macroLCK_RW_DEFINE
#define LCK_RW_DEFINE(var, grp) LCK_RW_DEFINE_ATTR(var, grp, LCK_ATTR_NULL)
macroLCK_RW_OLD_DEFINE
#define LCK_RW_OLD_DEFINE(var, grp) lck_rw_old_t var;
static __startup_data struct lck_rw_old_startup_spec
__startup_lck_rw_spec_ ## var = { &var, grp, NULL };
STARTUP_ARG(LOCKS, STARTUP_RANK_FOURTH, lck_rw_old_startup_init,
&__startup_lck_rw_spec_ ## var)macroLCK_RW_NEW_DEFINE
#define LCK_RW_NEW_DEFINE(var, grp) lck_rw_new_t var;
static __startup_data struct lck_rw_new_startup_spec
__startup_lck_rw_spec_ ## var = { &var, grp, NULL };
STARTUP_ARG(LOCKS, STARTUP_RANK_FOURTH, lck_rw_new_startup_init,
&__startup_lck_rw_spec_ ## var)functionlck_rw_alloc_init
extern lck_rw_t *lck_rw_alloc_init(lck_grp_t *grp, lck_attr_t *attr)
@function lck_rw_alloc_init
@abstract Allocates and initializes a rw_lock_t.
@discussion The function can block. See lck_rw_init() for initialization details.
@param grp lock group to associate with the lock.
@param attr lock attribute to initialize the lock.
@returns NULL or the allocated lock
functionlck_rw_init
extern void lck_rw_init(lck_rw_t *lck, lck_grp_t *grp, lck_attr_t *attr)
@function lck_rw_init
@abstract Initializes a rw_lock_t.
@discussion Usage statistics for the lock are going to be added to the lock group provided.
The lock attribute can be LCK_ATTR_NULL or an attribute can be allocated with
lck_attr_alloc_init. So far however none of the attribute settings are supported.
@param lck lock to initialize.
@param grp lock group to associate with the lock.
@param attr lock attribute to initialize the lock.
functionlck_rw_free
extern void lck_rw_free(lck_rw_t *lck, lck_grp_t *grp)
@function lck_rw_free
@abstract Frees a rw_lock previously allocated with lck_rw_alloc_init().
@discussion The lock must be not held by any thread.
@param lck rw_lock to free.
functionlck_rw_destroy
extern void lck_rw_destroy(lck_rw_t *lck, lck_grp_t *grp)
@function lck_rw_destroy
@abstract Destroys a rw_lock previously initialized with lck_rw_init().
@discussion The lock must be not held by any thread.
@param lck rw_lock to destroy.
macroLCK_RW_DECLARE_ATTR
obsolete names, use LCK_RW_DEFINE* instead
#define LCK_RW_DECLARE_ATTR(...) LCK_RW_DEFINE_ATTR(__VA_ARGS__)
macroLCK_RW_DECLARE
#define LCK_RW_DECLARE(...) LCK_RW_DEFINE(__VA_ARGS__)
enumlck_rw_type_t
| LCK_RW_TYPE_SHARED | 1 | |
| LCK_RW_TYPE_EXCLUSIVE | 2 |
typedeflck_rw_type_t
typedef enum lck_rw_type_t lck_rw_type_t;
functionlck_rw_lock
extern void lck_rw_lock(lck_rw_t *lck, lck_rw_type_t lck_rw_type)
@function lck_rw_lock
@abstract Locks a rw_lock with the specified type.
@discussion See lck_rw_lock_shared() or lck_rw_lock_exclusive() for more details.
@param lck rw_lock to lock.
@param lck_rw_type LCK_RW_TYPE_SHARED or LCK_RW_TYPE_EXCLUSIVE
functionlck_rw_try_lock
__result_use_check extern boolean_t lck_rw_try_lock(lck_rw_t *lck, lck_rw_type_t lck_rw_type)
@function lck_rw_try_lock
@abstract Tries to lock a rw_lock with the specified type.
@discussion This function will return and not wait/block in case the lock is already held.
See lck_rw_try_lock_shared() or lck_rw_try_lock_exclusive() for more details.
@param lck rw_lock to lock.
@param lck_rw_type LCK_RW_TYPE_SHARED or LCK_RW_TYPE_EXCLUSIVE
@returns TRUE if the lock is successfully acquired, FALSE in case it was already held.
functionlck_rw_unlock
extern void lck_rw_unlock(lck_rw_t *lck, lck_rw_type_t lck_rw_type)
@function lck_rw_unlock
@abstract Unlocks a rw_lock previously locked with lck_rw_type.
@discussion The lock must be unlocked by the same thread it was locked from.
The type of the lock/unlock have to match, unless an upgrade/downgrade was performed while
holding the lock.
@param lck rw_lock to unlock.
@param lck_rw_type LCK_RW_TYPE_SHARED or LCK_RW_TYPE_EXCLUSIVE
functionlck_rw_lock_exclusive
extern void lck_rw_lock_exclusive(lck_rw_t *lck)
@function lck_rw_lock_exclusive
@abstract Locks a rw_lock in exclusive mode.
@discussion This function can block.
Multiple threads can acquire the lock in shared mode at the same time,
but only one thread at a time can acquire it in exclusive mode.
NOTE: the thread cannot return to userspace while the lock is held.
Recursive locking is not supported.
@param lck rw_lock to lock.
functionlck_rw_unlock_exclusive
extern void lck_rw_unlock_exclusive(lck_rw_t *lck)
@function lck_rw_unlock_exclusive
@abstract Unlocks a rw_lock previously locked in exclusive mode.
@discussion The same thread that locked the lock needs to unlock it.
@param lck rw_lock held in exclusive mode to unlock.
functionlck_rw_sleep
extern wait_result_t lck_rw_sleep( lck_rw_t *lck, lck_sleep_action_t lck_sleep_action, event_t event, wait_interrupt_t interruptible )
@function lck_rw_sleep
@abstract Assert_wait on an event while holding the rw_lock.
@discussion the flags can decide how to re-acquire the lock upon wake up
(LCK_SLEEP_SHARED, or LCK_SLEEP_EXCLUSIVE, or LCK_SLEEP_UNLOCK)
and if the priority needs to be kept boosted until the lock is
re-acquired (LCK_SLEEP_PROMOTED_PRI).
@param lck rw_lock to use to synch the assert_wait.
@param lck_sleep_action flags.
@param event event to assert_wait on.
@param interruptible wait type.
functionlck_rw_sleep_deadline
extern wait_result_t lck_rw_sleep_deadline( lck_rw_t *lck, lck_sleep_action_t lck_sleep_action, event_t event, wait_interrupt_t interruptible, uint64_t deadline )
@function lck_rw_sleep_deadline
@abstract Assert_wait_deadline on an event while holding the rw_lock.
@discussion the flags can decide how to re-acquire the lock upon wake up
(LCK_SLEEP_SHARED, or LCK_SLEEP_EXCLUSIVE, or LCK_SLEEP_UNLOCK)
and if the priority needs to be kept boosted until the lock is
re-acquired (LCK_SLEEP_PROMOTED_PRI).
@param lck rw_lock to use to synch the assert_wait.
@param lck_sleep_action flags.
@param event event to assert_wait on.
@param interruptible wait type.
@param deadline maximum time after which being woken up