21 #ifndef __TBB_spin_rw_mutex_H 22 #define __TBB_spin_rw_mutex_H 31 #if __TBB_TSX_AVAILABLE 32 namespace interface8 {
namespace internal {
33 class x86_rtm_rw_mutex;
75 #if TBB_USE_THREADING_TOOLS 83 __TBB_ASSERT( !state,
"destruction of an acquired mutex");
91 #if __TBB_TSX_AVAILABLE 92 friend class tbb::interface8::internal::x86_rtm_rw_mutex;
110 void acquire( spin_rw_mutex& m,
bool write =
true ) {
114 if( write )
mutex->internal_acquire_writer();
115 else mutex->internal_acquire_reader();
124 return mutex->internal_upgrade();
130 spin_rw_mutex *m =
mutex;
132 #if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT 145 #if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT 146 mutex->internal_downgrade();
148 __TBB_FetchAndAddW( &
mutex->state, ((intptr_t)ONE_READER-WRITER));
177 static const bool is_rw_mutex =
true;
178 static const bool is_recursive_mutex =
false;
179 static const bool is_fair_mutex =
false;
184 void lock() {internal_acquire_writer();}
188 bool try_lock() {
return internal_try_acquire_writer();}
192 #if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT 193 if( state&WRITER ) internal_release_writer();
194 else internal_release_reader();
212 static const state_t WRITER = 1;
213 static const state_t WRITER_PENDING = 2;
214 static const state_t READERS = ~(WRITER | WRITER_PENDING);
215 static const state_t ONE_READER = 4;
216 static const state_t BUSY = WRITER | READERS;
231 #if __TBB_TSX_AVAILABLE 236 namespace interface8 {
246 #if __TBB_TSX_AVAILABLE state_t state
State of lock.
void release()
Release lock.
bool try_lock()
Try acquiring writer lock (non-blocking)
spin_rw_mutex * mutex
The pointer to the current mutex that is held, or NULL if no mutex is held.
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
void lock_read()
Acquire reader lock.
#define __TBB_FetchAndAddWrelease(P, V)
void __TBB_AtomicAND(volatile void *operand, uintptr_t addend)
~scoped_lock()
Release lock (if lock is held).
bool downgrade_to_reader()
Downgrade writer to become a reader.
The scoped locking pattern.
scoped_lock()
Construct lock that has not acquired a mutex.
#define __TBB_EXPORTED_METHOD
bool try_acquire(spin_rw_mutex &m, bool write=true)
Try acquire lock on given mutex.
bool __TBB_EXPORTED_METHOD internal_try_acquire_reader()
Internal try_acquire read lock.
void acquire(spin_rw_mutex &m, bool write=true)
Acquire lock on given mutex.
spin_rw_mutex_v3()
Construct unacquired mutex.
#define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type)
void lock()
Acquire writer lock.
void unlock()
Release lock.
spin_rw_mutex_v3 spin_rw_mutex
bool try_lock_read()
Try acquiring reader lock (non-blocking)
void __TBB_EXPORTED_METHOD internal_release_writer()
Out of line code for releasing a write lock.
Wrapper around the platform's native lock.
bool is_writer
If mutex!=NULL, then is_writer is true if holding a writer lock, false if holding a reader lock...
void __TBB_EXPORTED_METHOD internal_release_reader()
Internal release read lock.
bool upgrade_to_writer()
Upgrade reader to become a writer.
scoped_lock(spin_rw_mutex &m, bool write=true)
Acquire lock on given mutex.
bool __TBB_EXPORTED_METHOD internal_try_acquire_writer()
Internal try_acquire write lock.
interface7::internal::padded_mutex< tbb::spin_rw_mutex, true > speculative_spin_rw_mutex
A cross-platform spin reader/writer mutex with speculative lock acquisition.
Fast, unfair, spinning reader-writer lock with backoff and writer-preference.