Intel(R) Threading Building Blocks Doxygen Documentation
version 4.2.3
|
The scoped locking pattern. More...
#include <queuing_mutex.h>
Public Member Functions | |
scoped_lock () | |
Construct lock that has not acquired a mutex. More... | |
scoped_lock (queuing_mutex &m) | |
Acquire lock on given mutex. More... | |
~scoped_lock () | |
Release lock (if lock is held). More... | |
void __TBB_EXPORTED_METHOD | acquire (queuing_mutex &m) |
Acquire lock on given mutex. More... | |
bool __TBB_EXPORTED_METHOD | try_acquire (queuing_mutex &m) |
Acquire lock on given mutex if free (i.e. non-blocking) More... | |
void __TBB_EXPORTED_METHOD | release () |
Release lock. More... | |
Private Member Functions | |
void | initialize () |
Initialize fields to mean "no lock held". More... | |
![]() | |
no_copy (const no_copy &)=delete | |
no_copy ()=default | |
Private Attributes | |
queuing_mutex * | mutex |
The pointer to the mutex owned, or NULL if not holding a mutex. More... | |
scoped_lock * | next |
The pointer to the next competitor for a mutex. More... | |
uintptr_t | going |
The local spin-wait variable. 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 44 of file queuing_mutex.h.
|
inline |
Construct lock that has not acquired a mutex.
Equivalent to zero-initialization of *this.
Definition at line 57 of file queuing_mutex.h.
References initialize().
|
inline |
Acquire lock on given mutex.
Definition at line 60 of file queuing_mutex.h.
References acquire(), and initialize().
|
inline |
Release lock (if lock is held).
Definition at line 66 of file queuing_mutex.h.
References mutex, and release().
void tbb::queuing_mutex::scoped_lock::acquire | ( | queuing_mutex & | m | ) |
Acquire lock on given mutex.
A method to acquire queuing_mutex lock.
Definition at line 28 of file queuing_mutex.cpp.
References __TBB_ASSERT, __TBB_control_consistency_helper, tbb::internal::__TBB_load_with_acquire(), ITT_NOTIFY, next, tbb::queuing_mutex::q_tail, tbb::release, and tbb::internal::spin_wait_while_eq().
Referenced by scoped_lock().
|
inlineprivate |
Initialize fields to mean "no lock held".
Definition at line 46 of file queuing_mutex.h.
References going, mutex, next, and tbb::internal::poison_pointer().
Referenced by scoped_lock().
void tbb::queuing_mutex::scoped_lock::release | ( | ) |
Release lock.
A method to release queuing_mutex lock.
Definition at line 81 of file queuing_mutex.cpp.
References __TBB_ASSERT, tbb::internal::__TBB_store_with_release(), ITT_NOTIFY, tbb::release, tbb::internal::spin_wait_while_eq(), and sync_releasing.
Referenced by ~scoped_lock().
bool tbb::queuing_mutex::scoped_lock::try_acquire | ( | queuing_mutex & | m | ) |
Acquire lock on given mutex if free (i.e. non-blocking)
A method to acquire queuing_mutex if it is free.
Definition at line 58 of file queuing_mutex.cpp.
References __TBB_ASSERT, tbb::internal::__TBB_load_with_acquire(), ITT_NOTIFY, tbb::queuing_mutex::q_tail, and tbb::release.
|
private |
The local spin-wait variable.
Inverted (0 - blocked, 1 - acquired the mutex) for the sake of zero-initialization. Defining it as an entire word instead of a byte seems to help performance slightly.
Definition at line 90 of file queuing_mutex.h.
Referenced by initialize().
|
private |
The pointer to the mutex owned, or NULL if not holding a mutex.
Definition at line 81 of file queuing_mutex.h.
Referenced by initialize(), and ~scoped_lock().
|
private |
The pointer to the next competitor for a mutex.
Definition at line 84 of file queuing_mutex.h.
Referenced by acquire(), and initialize().