18 #if __TBB_TSX_AVAILABLE 29 #ifndef __TBB_RW_MUTEX_DELAY_TEST 30 #define __TBB_RW_MUTEX_DELAY_TEST 0 33 #if defined(_MSC_VER) && defined(_Wp64) 35 #pragma warning (disable: 4244) 40 namespace interface8 {
46 speculation_transaction_aborted = 0x01,
47 speculation_can_retry = 0x02,
48 speculation_memadd_conflict = 0x04,
49 speculation_buffer_overflow = 0x08,
50 speculation_breakpoint_hit = 0x10,
51 speculation_nested_abort = 0x20,
52 speculation_xabort_mask = 0xFF000000,
53 speculation_xabort_shift = 24,
54 speculation_retry = speculation_transaction_aborted
55 | speculation_can_retry
56 | speculation_memadd_conflict
61 static const int retry_threshold_read = 10;
62 static const int retry_threshold_write = 10;
65 void x86_rtm_rw_mutex::internal_release(x86_rtm_rw_mutex::scoped_lock&
s) {
66 switch(
s.transaction_state) {
67 case RTM_transacting_writer:
68 case RTM_transacting_reader:
71 #if __TBB_RW_MUTEX_DELAY_TEST 72 if(
s.transaction_state == RTM_transacting_reader) {
79 s.my_scoped_lock.mutex = NULL;
83 __TBB_ASSERT(!this->w_flag,
"w_flag set but read lock acquired");
84 s.my_scoped_lock.release();
87 __TBB_ASSERT(this->w_flag,
"w_flag unset but write lock acquired");
89 s.my_scoped_lock.release();
91 case RTM_not_in_mutex:
97 s.transaction_state = RTM_not_in_mutex;
101 void x86_rtm_rw_mutex::internal_acquire_writer(x86_rtm_rw_mutex::scoped_lock&
s,
bool only_speculate)
103 __TBB_ASSERT(
s.transaction_state == RTM_not_in_mutex,
"scoped_lock already in transaction");
106 unsigned int abort_code;
110 if(only_speculate)
return;
113 }
while(this->state);
119 #if !__TBB_RW_MUTEX_DELAY_TEST 125 s.transaction_state = RTM_transacting_writer;
128 s.my_scoped_lock.mutex =
this;
132 }
while( (abort_code & speculation_retry) != 0 && (num_retries < retry_threshold_write) );
135 if(only_speculate)
return;
136 s.my_scoped_lock.acquire(*
this,
true);
137 __TBB_ASSERT(!w_flag,
"After acquire for write, w_flag already true");
139 s.transaction_state = RTM_real_writer;
147 void x86_rtm_rw_mutex::internal_acquire_reader(x86_rtm_rw_mutex::scoped_lock&
s,
bool only_speculate) {
148 __TBB_ASSERT(
s.transaction_state == RTM_not_in_mutex,
"scoped_lock already in transaction");
151 unsigned int abort_code;
156 if(only_speculate)
return;
165 #if !__TBB_RW_MUTEX_DELAY_TEST 170 s.transaction_state = RTM_transacting_reader;
173 s.my_scoped_lock.mutex =
this;
186 }
while( (abort_code & speculation_retry) != 0 && (num_retries < retry_threshold_read) );
189 if(only_speculate)
return;
190 s.my_scoped_lock.acquire( *
this,
false );
191 s.transaction_state = RTM_real_reader;
196 bool x86_rtm_rw_mutex::internal_upgrade(x86_rtm_rw_mutex::scoped_lock&
s)
198 switch(
s.transaction_state) {
199 case RTM_real_reader: {
200 s.transaction_state = RTM_real_writer;
201 bool no_release =
s.my_scoped_lock.upgrade_to_writer();
202 __TBB_ASSERT(!w_flag,
"After upgrade_to_writer, w_flag already true");
206 case RTM_transacting_reader:
207 #if !__TBB_RW_MUTEX_DELAY_TEST 211 internal_acquire_writer(
s);
216 s.transaction_state = RTM_transacting_writer;
226 bool x86_rtm_rw_mutex::internal_downgrade(x86_rtm_rw_mutex::scoped_lock&
s) {
227 switch(
s.transaction_state) {
228 case RTM_real_writer:
229 s.transaction_state = RTM_real_reader;
230 __TBB_ASSERT(w_flag,
"Before downgrade_to_reader w_flag not true");
232 return s.my_scoped_lock.downgrade_to_reader();
233 case RTM_transacting_writer:
234 #if __TBB_RW_MUTEX_DELAY_TEST 239 s.transaction_state = RTM_transacting_reader;
252 bool x86_rtm_rw_mutex::internal_try_acquire_writer(x86_rtm_rw_mutex::scoped_lock&
s)
254 internal_acquire_writer(
s,
true);
255 if(
s.transaction_state == RTM_transacting_writer) {
258 __TBB_ASSERT(
s.transaction_state == RTM_not_in_mutex,
"Trying to acquire writer which is already allocated");
260 bool result =
s.my_scoped_lock.try_acquire(*
this,
true);
263 __TBB_ASSERT(!w_flag,
"After try_acquire_writer, w_flag already true");
265 s.transaction_state = RTM_real_writer;
270 void x86_rtm_rw_mutex::internal_construct() {
void __TBB_EXPORTED_FUNC __TBB_machine_end_transaction()
void __TBB_EXPORTED_FUNC __TBB_machine_transaction_conflict_abort()
__int8 __TBB_EXPORTED_FUNC __TBB_machine_is_in_transaction()
void pause()
Pause for a while.
unsigned __int32 __TBB_EXPORTED_FUNC __TBB_machine_begin_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
#define ITT_SYNC_CREATE(obj, type, name)
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
static bool speculation_enabled()