22 #if __TBB_TSX_AVAILABLE 33 #ifndef __TBB_RW_MUTEX_DELAY_TEST 34 #define __TBB_RW_MUTEX_DELAY_TEST 0 37 #if defined(_MSC_VER) && defined(_Wp64) 39 #pragma warning (disable: 4244) 44 namespace interface8 {
50 speculation_transaction_aborted = 0x01,
51 speculation_can_retry = 0x02,
52 speculation_memadd_conflict = 0x04,
53 speculation_buffer_overflow = 0x08,
54 speculation_breakpoint_hit = 0x10,
55 speculation_nested_abort = 0x20,
56 speculation_xabort_mask = 0xFF000000,
57 speculation_xabort_shift = 24,
58 speculation_retry = speculation_transaction_aborted
59 | speculation_can_retry
60 | speculation_memadd_conflict
65 static const int retry_threshold_read = 10;
66 static const int retry_threshold_write = 10;
69 void x86_rtm_rw_mutex::internal_release(x86_rtm_rw_mutex::scoped_lock&
s) {
70 switch(
s.transaction_state) {
71 case RTM_transacting_writer:
72 case RTM_transacting_reader:
75 #if __TBB_RW_MUTEX_DELAY_TEST 76 if(
s.transaction_state == RTM_transacting_reader) {
83 s.my_scoped_lock.mutex = NULL;
87 __TBB_ASSERT(!this->w_flag,
"w_flag set but read lock acquired");
88 s.my_scoped_lock.release();
91 __TBB_ASSERT(this->w_flag,
"w_flag unset but write lock acquired");
93 s.my_scoped_lock.release();
95 case RTM_not_in_mutex:
101 s.transaction_state = RTM_not_in_mutex;
105 void x86_rtm_rw_mutex::internal_acquire_writer(x86_rtm_rw_mutex::scoped_lock&
s,
bool only_speculate)
107 __TBB_ASSERT(
s.transaction_state == RTM_not_in_mutex,
"scoped_lock already in transaction");
110 unsigned int abort_code;
114 if(only_speculate)
return;
117 }
while(this->state);
123 #if !__TBB_RW_MUTEX_DELAY_TEST 129 s.transaction_state = RTM_transacting_writer;
132 s.my_scoped_lock.mutex =
this;
136 }
while( (abort_code & speculation_retry) != 0 && (num_retries < retry_threshold_write) );
139 if(only_speculate)
return;
140 s.my_scoped_lock.acquire(*
this,
true);
141 __TBB_ASSERT(!w_flag,
"After acquire for write, w_flag already true");
143 s.transaction_state = RTM_real_writer;
151 void x86_rtm_rw_mutex::internal_acquire_reader(x86_rtm_rw_mutex::scoped_lock&
s,
bool only_speculate) {
152 __TBB_ASSERT(
s.transaction_state == RTM_not_in_mutex,
"scoped_lock already in transaction");
155 unsigned int abort_code;
160 if(only_speculate)
return;
169 #if !__TBB_RW_MUTEX_DELAY_TEST 174 s.transaction_state = RTM_transacting_reader;
177 s.my_scoped_lock.mutex =
this;
190 }
while( (abort_code & speculation_retry) != 0 && (num_retries < retry_threshold_read) );
193 if(only_speculate)
return;
194 s.my_scoped_lock.acquire( *
this,
false );
195 s.transaction_state = RTM_real_reader;
200 bool x86_rtm_rw_mutex::internal_upgrade(x86_rtm_rw_mutex::scoped_lock&
s)
202 switch(
s.transaction_state) {
203 case RTM_real_reader: {
204 s.transaction_state = RTM_real_writer;
205 bool no_release =
s.my_scoped_lock.upgrade_to_writer();
206 __TBB_ASSERT(!w_flag,
"After upgrade_to_writer, w_flag already true");
210 case RTM_transacting_reader:
211 #if !__TBB_RW_MUTEX_DELAY_TEST 215 internal_acquire_writer(
s);
220 s.transaction_state = RTM_transacting_writer;
230 bool x86_rtm_rw_mutex::internal_downgrade(x86_rtm_rw_mutex::scoped_lock&
s) {
231 switch(
s.transaction_state) {
232 case RTM_real_writer:
233 s.transaction_state = RTM_real_reader;
234 __TBB_ASSERT(w_flag,
"Before downgrade_to_reader w_flag not true");
236 return s.my_scoped_lock.downgrade_to_reader();
237 case RTM_transacting_writer:
238 #if __TBB_RW_MUTEX_DELAY_TEST 243 s.transaction_state = RTM_transacting_reader;
256 bool x86_rtm_rw_mutex::internal_try_acquire_writer(x86_rtm_rw_mutex::scoped_lock&
s)
258 internal_acquire_writer(
s,
true);
259 if(
s.transaction_state == RTM_transacting_writer) {
262 __TBB_ASSERT(
s.transaction_state == RTM_not_in_mutex,
"Trying to acquire writer which is already allocated");
264 bool result =
s.my_scoped_lock.try_acquire(*
this,
true);
267 __TBB_ASSERT(!w_flag,
"After try_acquire_writer, w_flag already true");
269 s.transaction_state = RTM_real_writer;
274 void x86_rtm_rw_mutex::internal_construct() {
__int8 __TBB_EXPORTED_FUNC __TBB_machine_is_in_transaction()
static bool speculation_enabled()
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
#define ITT_SYNC_CREATE(obj, type, name)
void pause()
Pause for a while.
void __TBB_EXPORTED_FUNC __TBB_machine_end_transaction()
#define _T(string_literal)
Standard Windows style macro to markup the string literals.
Class that implements exponential backoff.
void const char const char int ITT_FORMAT __itt_group_sync s
unsigned __int32 __TBB_EXPORTED_FUNC __TBB_machine_begin_transaction()
void __TBB_EXPORTED_FUNC __TBB_machine_transaction_conflict_abort()