void
rw_init(
krwlock_t *rw
)
void
rw_destroy(
krwlock_t *rw
)
void
rw_enter(
krwlock_t *rw
, const krw_t op
)
void
rw_exit(
krwlock_t *rw
)
int
rw_tryenter(
krwlock_t *rw
, const krw_t op
)
int
rw_tryupgrade(
krwlock_t *rw
)
void
rw_downgrade(
krwlock_t *rw
)
int
rw_read_held(
krwlock_t *rw
)
int
rw_write_held(
krwlock_t *rw
)
int
rw_lock_held(
krwlock_t *rw
)
options DIAGNOSTIC options LOCKDEBUG
In addition to the capabilities provided by mutexes, RW locks distinguish between read (shared) and write (exclusive) access. RW locks are intended to provide protection for kernel data or objects that are read much more frequently than updated. For objects that are updated as frequently as they are read, mutexes should be used to guarantee atomic access.
RW locks are in one of three distinct states at any given time:
Unlocked
Read
locked
Write
locked
The type provides storage for the RW lock object. This should be treated as an opaque object and not examined directly by consumers.
Note that the these interfaces must not be used from a hardware interrupt handler.
Kernels compiled with the
DIAGNOSTIC
option perform basic sanity checks on RW lock operations.
Kernels compiled with the
LOCKDEBUG
option perform potentially CPU intensive sanity checks
on RW lock operations.
rw
)Initialize a lock for use. No other operations can be performed on the lock until it has been initialized.
rw
)Release resources used by a lock. The lock may not be used after it has been destroyed.
rw
, op
)
If
RW_READER
is specified as the argument to
op
,
acquire a read lock.
If the lock is write held, the caller will block and not return until the
hold is acquired.
Callers must not recursively acquire read locks.
If
RW_WRITER
is specified, acquire a write lock.
If the lock is already held, the caller will block and not return until the
hold is acquired.
RW locks and other types of locks must always be acquired in a consistent order with respect to each other. Otherwise, the potential for system deadlock exists.
rw
)Release a lock. The lock must have been previously acquired by the caller.
rw
, op
)Try to acquire a lock, but do not block if the lock is already held. If the lock is acquired successfully, return non-zero. Otherwise, return zero.
Valid arguments to
op
are
RW_READER
or
RW_WRITER
.
rw
)Try to upgrade a lock from one read hold to a write hold. If the lock is upgraded successfully, returns non-zero. Otherwise, returns zero.
rw
)Downgrade a lock from a write hold to a read hold.
rw
)
rw
)
rw
)Test the lock's condition and return non-zero if the lock is held (potentially by the current LWP) and matches the specified condition. Otherwise, return zero.
These functions must never be used to make locking decisions at run time: they are provided only for diagnostic purposes.
/usr/src
.
The core of the RW lock implementation is in
sys/kern/kern_rwlock.c
.
The header file
sys/sys/rwlock.h
describes the public interface, and interfaces that machine-dependent
code must provide to support RW locks.