This read-write lock is implemented around a queue-based lock. It is the basis for latches in the storage manager.
Use this to protect data structures that get constantly hammered by short reads, and less frequently (but still often) by short writes.
"Short" is the key word here, since this is spin-based.
Definition at line 73 of file srwlock.h.
Public Types | |
enum | rwmode_t |
Public Member Functions | |
mcs_rwlock () | |
~mcs_rwlock () | |
rwmode_t | mode () const |
Return the mode in which this lock is held by anyone. | |
bool | is_locked () const |
True if locked in any mode. | |
int | num_holders () const |
1 if held in write mode, else it's the number of readers | |
bool | has_reader () const |
True iff has one or more readers. | |
bool | has_writer () const |
True iff has a writer (never more than 1). | |
bool | attempt_read () |
True if success. | |
void | acquire_read () |
Wait (spin) until acquired. | |
void | release_read () |
This thread had better hold the lock in read mode. | |
bool | attempt_write () |
True if success. | |
void | acquire_write () |
Wait (spin) until acquired. | |
void | release_write () |
This thread had better hold the lock in write mode. | |
bool | attempt_upgrade () |
Try to upgrade from READ to WRITE mode. Fail if any other threads are waiting. | |
void | downgrade () |
Atomically downgrade the lock from WRITE to READ mode. |