Reader / writer locks (RW locks) are used in the kernel to synchronize access to an object among LWPs (lightweight processes) and soft interrupt handlers.
In addition to the capabilities provided by mutexes, RW locks distinguish between read (shared) and write (exclusive) access.
RW locks are in one of three distinct states at any given time:
Unlocked
The lock is not held.
Read locked
The lock holders intend to read the protected object. Multiple callers may hold a RW lock with “read intent” simultaneously.
Write locked
The lock holder intends to update the protected object. Only one caller may hold a RW lock with “write intent”.
The
krwlock_t type provides storage for the RW lock object. This should be treated as an opaque object and not examined directly by consumers.
Note that these interfaces must not be used from a hardware interrupt handler.