Intel(R) Threading Building Blocks Doxygen Documentation
version 4.2.3
|
The scoped locking pattern. More...
#include <queuing_rw_mutex.h>
Public Member Functions | |
scoped_lock () | |
Construct lock that has not acquired a mutex. More... | |
scoped_lock (queuing_rw_mutex &m, bool write=true) | |
Acquire lock on given mutex. More... | |
~scoped_lock () | |
Release lock (if lock is held). More... | |
void | acquire (queuing_rw_mutex &m, bool write=true) |
Acquire lock on given mutex. More... | |
bool | try_acquire (queuing_rw_mutex &m, bool write=true) |
Acquire lock on given mutex if free (i.e. non-blocking) More... | |
void | release () |
Release lock. More... | |
bool | upgrade_to_writer () |
Upgrade reader to become a writer. More... | |
bool | downgrade_to_reader () |
Downgrade writer to become a reader. More... | |
Private Types | |
typedef unsigned char | state_t |
Private Member Functions | |
void | initialize () |
Initialize fields to mean "no lock held". More... | |
void | acquire_internal_lock () |
Acquire the internal lock. More... | |
bool | try_acquire_internal_lock () |
Try to acquire the internal lock. More... | |
void | release_internal_lock () |
Release the internal lock. More... | |
void | wait_for_release_of_internal_lock () |
Wait for internal lock to be released. More... | |
void | unblock_or_wait_on_internal_lock (uintptr_t) |
A helper function. More... | |
![]() | |
no_copy (const no_copy &)=delete | |
no_copy ()=default | |
Private Attributes | |
queuing_rw_mutex * | my_mutex |
The pointer to the mutex owned, or NULL if not holding a mutex. More... | |
scoped_lock *__TBB_atomic | my_prev |
The pointer to the previous and next competitors for a mutex. More... | |
scoped_lock *__TBB_atomic *__TBB_atomic | my_next |
atomic< state_t > | my_state |
State of the request: reader, writer, active reader, other service states. More... | |
unsigned char __TBB_atomic | my_going |
The local spin-wait variable. More... | |
unsigned char | my_internal_lock |
A tiny internal lock. More... | |
The scoped locking pattern.
It helps to avoid the common problem of forgetting to release lock. It also nicely provides the "node" for queuing locks.
Definition at line 53 of file queuing_rw_mutex.h.
|
private |
Definition at line 105 of file queuing_rw_mutex.h.
|
inline |
Construct lock that has not acquired a mutex.
Equivalent to zero-initialization of *this.
Definition at line 69 of file queuing_rw_mutex.h.
References initialize().
|
inline |
Acquire lock on given mutex.
Definition at line 72 of file queuing_rw_mutex.h.
References acquire(), and initialize().
|
inline |
Release lock (if lock is held).
Definition at line 78 of file queuing_rw_mutex.h.
References my_mutex, and release().
void tbb::queuing_rw_mutex::scoped_lock::acquire | ( | queuing_rw_mutex & | m, |
bool | write = true |
||
) |
Acquire lock on given mutex.
A method to acquire queuing_rw_mutex lock.
Definition at line 140 of file queuing_rw_mutex.cpp.
References __TBB_ASSERT, __TBB_control_consistency_helper, tbb::internal::__TBB_load_relaxed(), tbb::internal::__TBB_load_with_acquire(), tbb::internal::__TBB_store_relaxed(), tbb::internal::__TBB_store_with_release(), tbb::acquire, tbb::FLAG, ITT_NOTIFY, my_next, my_state, tbb::queuing_rw_mutex::q_tail, tbb::release, tbb::RELEASED, tbb::internal::spin_wait_until_eq(), tbb::internal::spin_wait_while_eq(), tbb::STATE_ACTIVEREADER, tbb::STATE_READER, tbb::STATE_READER_UNBLOCKNEXT, tbb::STATE_UPGRADE_WAITING, and tbb::STATE_WRITER.
Referenced by scoped_lock().
|
inlineprivate |
Acquire the internal lock.
Definition at line 55 of file queuing_rw_mutex.cpp.
References __TBB_Pause().
bool tbb::queuing_rw_mutex::scoped_lock::downgrade_to_reader | ( | ) |
Downgrade writer to become a reader.
Definition at line 360 of file queuing_rw_mutex.cpp.
References __TBB_ASSERT, tbb::internal::__TBB_load_relaxed(), tbb::internal::__TBB_load_with_acquire(), tbb::internal::__TBB_store_with_release(), tbb::full_fence, ITT_NOTIFY, my_going, my_state, tbb::release, tbb::internal::spin_wait_while_eq(), tbb::STATE_ACTIVEREADER, tbb::STATE_COMBINED_WAITINGREADER, tbb::STATE_READER, tbb::STATE_UPGRADE_LOSER, tbb::STATE_UPGRADE_WAITING, and sync_releasing.
|
inlineprivate |
Initialize fields to mean "no lock held".
Definition at line 55 of file queuing_rw_mutex.h.
References my_going, my_internal_lock, my_mutex, my_next, my_prev, my_state, and tbb::internal::poison_pointer().
Referenced by scoped_lock().
void tbb::queuing_rw_mutex::scoped_lock::release | ( | ) |
Release lock.
A method to release queuing_rw_mutex lock.
Definition at line 254 of file queuing_rw_mutex.cpp.
References __TBB_ASSERT, tbb::internal::__TBB_load_relaxed(), tbb::internal::__TBB_load_with_acquire(), tbb::internal::__TBB_store_relaxed(), tbb::internal::__TBB_store_with_release(), tbb::ACQUIRED, tbb::FLAG, tbb::get_flag(), ITT_NOTIFY, my_going, my_internal_lock, my_next, my_prev, my_state, tbb::release, release_internal_lock(), tbb::internal::spin_wait_while_eq(), tbb::STATE_COMBINED_WAITINGREADER, tbb::STATE_UPGRADE_LOSER, tbb::STATE_UPGRADE_WAITING, tbb::STATE_WRITER, sync_releasing, and try_acquire_internal_lock().
Referenced by ~scoped_lock().
|
inlineprivate |
Release the internal lock.
Definition at line 64 of file queuing_rw_mutex.cpp.
References tbb::internal::__TBB_store_with_release(), and tbb::RELEASED.
Referenced by release().
bool tbb::queuing_rw_mutex::scoped_lock::try_acquire | ( | queuing_rw_mutex & | m, |
bool | write = true |
||
) |
Acquire lock on given mutex if free (i.e. non-blocking)
A method to acquire queuing_rw_mutex if it is free.
Definition at line 226 of file queuing_rw_mutex.cpp.
References __TBB_ASSERT, tbb::internal::__TBB_load_with_acquire(), tbb::internal::__TBB_store_relaxed(), ITT_NOTIFY, tbb::queuing_rw_mutex::q_tail, tbb::release, tbb::RELEASED, tbb::STATE_ACTIVEREADER, and tbb::STATE_WRITER.
|
inlineprivate |
Try to acquire the internal lock.
Returns true if lock was successfully acquired.
Definition at line 50 of file queuing_rw_mutex.cpp.
References tbb::acquire, tbb::ACQUIRED, tbb::internal::as_atomic(), and tbb::RELEASED.
Referenced by release().
|
inlineprivate |
A helper function.
Definition at line 74 of file queuing_rw_mutex.cpp.
bool tbb::queuing_rw_mutex::scoped_lock::upgrade_to_writer | ( | ) |
Upgrade reader to become a writer.
Returns whether the upgrade happened without releasing and re-acquiring the lock
Definition at line 387 of file queuing_rw_mutex.cpp.
References __TBB_ASSERT, __TBB_control_consistency_helper, tbb::internal::__TBB_load_relaxed(), tbb::internal::__TBB_load_with_acquire(), tbb::internal::__TBB_store_relaxed(), tbb::internal::__TBB_store_with_release(), tbb::acquire, tbb::FLAG, tbb::get_flag(), ITT_NOTIFY, my_going, my_prev, my_state, tbb::release, tbb::internal::spin_wait_while_eq(), tbb::STATE_COMBINED_READER, tbb::STATE_COMBINED_UPGRADING, tbb::STATE_COMBINED_WAITINGREADER, tbb::STATE_UPGRADE_LOSER, tbb::STATE_UPGRADE_REQUESTED, tbb::STATE_UPGRADE_WAITING, tbb::STATE_WRITER, and sync_releasing.
|
inlineprivate |
Wait for internal lock to be released.
Definition at line 69 of file queuing_rw_mutex.cpp.
References tbb::RELEASED, and tbb::internal::spin_wait_until_eq().
|
private |
The local spin-wait variable.
Corresponds to "spin" in the pseudocode but inverted for the sake of zero-initialization
Definition at line 112 of file queuing_rw_mutex.h.
Referenced by downgrade_to_reader(), initialize(), release(), and upgrade_to_writer().
|
private |
A tiny internal lock.
Definition at line 115 of file queuing_rw_mutex.h.
Referenced by initialize(), and release().
|
private |
The pointer to the mutex owned, or NULL if not holding a mutex.
Definition at line 100 of file queuing_rw_mutex.h.
Referenced by initialize(), and ~scoped_lock().
|
private |
Definition at line 103 of file queuing_rw_mutex.h.
Referenced by acquire(), initialize(), and release().
|
private |
The pointer to the previous and next competitors for a mutex.
Definition at line 103 of file queuing_rw_mutex.h.
Referenced by initialize(), release(), and upgrade_to_writer().
|
private |
State of the request: reader, writer, active reader, other service states.
Definition at line 108 of file queuing_rw_mutex.h.
Referenced by acquire(), downgrade_to_reader(), initialize(), release(), and upgrade_to_writer().