21 #ifndef __TBB__x86_rtm_rw_mutex_impl_H 22 #define __TBB__x86_rtm_rw_mutex_impl_H 24 #ifndef __TBB_spin_rw_mutex_H 25 #error Do not #include this internal file directly; use public TBB headers instead. 28 #if __TBB_TSX_AVAILABLE 30 #include "../tbb_stddef.h" 31 #include "../tbb_machine.h" 32 #include "../tbb_profiling.h" 33 #include "../spin_rw_mutex.h" 36 namespace interface8 {
41 RTM_transacting_reader,
42 RTM_transacting_writer,
47 static const unsigned long speculation_granularity = 64;
52 class x86_rtm_rw_mutex:
private spin_rw_mutex {
53 #if __TBB_USE_X86_RTM_RW_MUTEX || __TBB_GCC_VERSION < 40000 60 friend class interface7::internal::padded_mutex<x86_rtm_rw_mutex,true>;
62 friend class scoped_lock;
67 void __TBB_EXPORTED_METHOD internal_construct();
71 void __TBB_EXPORTED_METHOD internal_acquire_writer(x86_rtm_rw_mutex::scoped_lock&,
bool only_speculate=
false);
75 void __TBB_EXPORTED_METHOD internal_acquire_reader(x86_rtm_rw_mutex::scoped_lock&,
bool only_speculate=
false);
78 bool __TBB_EXPORTED_METHOD internal_upgrade( x86_rtm_rw_mutex::scoped_lock& );
81 bool __TBB_EXPORTED_METHOD internal_downgrade( x86_rtm_rw_mutex::scoped_lock& );
84 bool __TBB_EXPORTED_METHOD internal_try_acquire_writer( x86_rtm_rw_mutex::scoped_lock& );
87 void __TBB_EXPORTED_METHOD internal_release( x86_rtm_rw_mutex::scoped_lock& );
89 static x86_rtm_rw_mutex* internal_get_mutex(
const spin_rw_mutex::scoped_lock& lock )
91 return static_cast<x86_rtm_rw_mutex*
>( lock.internal_get_mutex() );
93 static void internal_set_mutex( spin_rw_mutex::scoped_lock& lock, spin_rw_mutex* mtx )
95 lock.internal_set_mutex( mtx );
102 #if TBB_USE_THREADING_TOOLS 103 internal_construct();
108 ~x86_rtm_rw_mutex() {}
113 static const bool is_rw_mutex =
true;
114 static const bool is_recursive_mutex =
false;
115 static const bool is_fair_mutex =
false;
117 #if __TBB_USE_X86_RTM_RW_MUTEX || __TBB_GCC_VERSION < 40000 132 class scoped_lock : tbb::internal::no_copy {
133 friend class x86_rtm_rw_mutex;
134 spin_rw_mutex::scoped_lock my_scoped_lock;
136 RTM_type transaction_state;
141 scoped_lock() : my_scoped_lock(), transaction_state(RTM_not_in_mutex) {
145 scoped_lock( x86_rtm_rw_mutex& m,
bool write =
true ) : my_scoped_lock(),
146 transaction_state(RTM_not_in_mutex) {
152 if(transaction_state != RTM_not_in_mutex)
release();
156 void acquire( x86_rtm_rw_mutex& m,
bool write =
true ) {
157 if( write ) m.internal_acquire_writer(*
this);
158 else m.internal_acquire_reader(*
this);
163 x86_rtm_rw_mutex* mutex = x86_rtm_rw_mutex::internal_get_mutex(my_scoped_lock);
164 __TBB_ASSERT( mutex,
"lock is not acquired" );
165 __TBB_ASSERT( transaction_state!=RTM_not_in_mutex,
"lock is not acquired" );
166 return mutex->internal_release(*
this);
171 bool upgrade_to_writer() {
172 x86_rtm_rw_mutex* mutex = x86_rtm_rw_mutex::internal_get_mutex(my_scoped_lock);
173 __TBB_ASSERT( mutex,
"lock is not acquired" );
174 __TBB_ASSERT( transaction_state==RTM_transacting_reader || transaction_state==RTM_real_reader,
"Invalid state for upgrade" );
175 return mutex->internal_upgrade(*
this);
180 bool downgrade_to_reader() {
181 x86_rtm_rw_mutex* mutex = x86_rtm_rw_mutex::internal_get_mutex(my_scoped_lock);
182 __TBB_ASSERT( mutex,
"lock is not acquired" );
183 __TBB_ASSERT( transaction_state==RTM_transacting_writer || transaction_state==RTM_real_writer,
"Invalid state for downgrade" );
184 return mutex->internal_downgrade(*
this);
189 bool try_acquire( x86_rtm_rw_mutex& m,
bool write =
true ) {
191 x86_rtm_rw_mutex* mutex = x86_rtm_rw_mutex::internal_get_mutex(my_scoped_lock);
192 __TBB_ASSERT( !mutex,
"lock is already acquired" );
196 if(write)
return m.internal_try_acquire_writer(*
this);
198 m.internal_acquire_reader(*
this,
true);
199 if(transaction_state == RTM_transacting_reader)
return true;
200 if( my_scoped_lock.try_acquire(m,
false)) {
201 transaction_state = RTM_real_reader;
213 char pad[speculation_granularity-
sizeof(spin_rw_mutex)];
Acquire.
Definition: atomic.h:47
Definition: _flow_graph_async_msg_impl.h:32
Release.
Definition: atomic.h:49
The namespace tbb contains all components of the library.
Definition: parallel_for.h:44