#include <reader_writer_lock.h>
Public Types | |
waiting_nonblocking | |
waiting | |
active | |
invalid | |
enum | status_t { waiting_nonblocking, waiting, active, invalid } |
Status type for nodes associated with lock instances. More... | |
Public Member Functions | |
reader_writer_lock () | |
Constructs a new reader_writer_lock. | |
~reader_writer_lock () | |
Destructs a reader_writer_lock object. | |
void __TBB_EXPORTED_METHOD | lock () |
Acquires the reader_writer_lock for write. | |
bool __TBB_EXPORTED_METHOD | try_lock () |
Tries to acquire the reader_writer_lock for write. | |
void __TBB_EXPORTED_METHOD | lock_read () |
Acquires the reader_writer_lock for read. | |
bool __TBB_EXPORTED_METHOD | try_lock_read () |
Tries to acquire the reader_writer_lock for read. | |
void __TBB_EXPORTED_METHOD | unlock () |
Releases the reader_writer_lock. | |
Friends | |
class | scoped_lock |
class | scoped_lock_read |
Classes | |
class | scoped_lock |
The scoped lock pattern for write locks. More... | |
class | scoped_lock_read |
The scoped lock pattern for read locks. More... |
Loosely adapted from Mellor-Crummey and Scott pseudocode at http://www.cs.rochester.edu/research/synchronization/pseudocode/rw.html#s_wp
Status type for nodes associated with lock instances.
waiting_nonblocking: the wait state for nonblocking lock instances; for writes, these transition straight to active states; for reads, these are unused.
waiting: the start and spin state for all lock instances; these will transition to active state when appropriate. Non-blocking write locks transition from this state to waiting_nonblocking immediately.
active: the active state means that the lock instance holds the lock; it will transition to invalid state during node deletion
invalid: the end state for all nodes; this is set in the destructor so if we encounter this state, we are looking at memory that has already been freed
The state diagrams below describe the status transitions. Single arrows indicate that the thread that owns the node is responsible for the transition; double arrows indicate that any thread could make the transition.
State diagram for scoped_lock status:
waiting ----------> waiting_nonblocking | _____________/ | V V V active -----------------> invalid
State diagram for scoped_lock_read status:
waiting | V active ----------------->invalid
void __TBB_EXPORTED_METHOD tbb::interface5::reader_writer_lock::lock | ( | ) |
Acquires the reader_writer_lock for write.
If the lock is currently held in write mode by another context, the writer will block by spinning on a local variable. Exceptions thrown: improper_lock The context tries to acquire a reader_writer_lock that it already has write ownership of.
void __TBB_EXPORTED_METHOD tbb::interface5::reader_writer_lock::lock_read | ( | ) |
Acquires the reader_writer_lock for read.
If the lock is currently held by a writer, this reader will block and wait until the writers are done. Exceptions thrown: improper_lock The context tries to acquire a reader_writer_lock that it already has write ownership of.
bool __TBB_EXPORTED_METHOD tbb::interface5::reader_writer_lock::try_lock | ( | ) |
Tries to acquire the reader_writer_lock for write.
This function does not block. Return Value: True or false, depending on whether the lock is acquired or not. If the lock is already held by this acquiring context, try_lock() returns false.
bool __TBB_EXPORTED_METHOD tbb::interface5::reader_writer_lock::try_lock_read | ( | ) |
Tries to acquire the reader_writer_lock for read.
This function does not block. Return Value: True or false, depending on whether the lock is acquired or not.