@@ -121,9 +121,9 @@ namespace hpx::detail {
121121
122122 bool try_lock_shared ()
123123 {
124+ auto s = state.load (std::memory_order_acquire);
124125 while (true )
125126 {
126- auto s = state.load (std::memory_order_acquire);
127127 if (s.data .exclusive || s.data .exclusive_waiting_blocked )
128128 {
129129 return false ;
@@ -136,6 +136,7 @@ namespace hpx::detail {
136136 {
137137 break ;
138138 }
139+ s = state.load (std::memory_order_acquire);
139140 }
140141 return true ;
141142 }
@@ -163,9 +164,9 @@ namespace hpx::detail {
163164
164165 void unlock_shared ()
165166 {
167+ auto s = state.load (std::memory_order_acquire);
166168 while (true )
167169 {
168- auto s = state.load (std::memory_order_acquire);
169170 auto s1 = s;
170171
171172 if (--s.data .shared_count == 0 )
@@ -205,14 +206,15 @@ namespace hpx::detail {
205206 {
206207 break ;
207208 }
209+ s = state.load (std::memory_order_acquire);
208210 }
209211 }
210212
211213 void lock ()
212214 {
215+ auto s = state.load (std::memory_order_acquire);
213216 while (true )
214217 {
215- auto s = state.load (std::memory_order_acquire);
216218 while (s.data .shared_count != 0 || s.data .exclusive )
217219 {
218220 auto s1 = s;
@@ -235,14 +237,15 @@ namespace hpx::detail {
235237 {
236238 break ;
237239 }
240+ s = state.load (std::memory_order_acquire);
238241 }
239242 }
240243
241244 bool try_lock ()
242245 {
246+ auto s = state.load (std::memory_order_acquire);
243247 while (true )
244248 {
245- auto s = state.load (std::memory_order_acquire);
246249 if (s.data .shared_count || s.data .exclusive )
247250 {
248251 return false ;
@@ -255,15 +258,16 @@ namespace hpx::detail {
255258 {
256259 break ;
257260 }
261+ s = state.load (std::memory_order_acquire);
258262 }
259263 return true ;
260264 }
261265
262266 void unlock ()
263267 {
268+ auto s = state.load (std::memory_order_acquire);
264269 while (true )
265270 {
266- auto s = state.load (std::memory_order_acquire);
267271 auto s1 = s;
268272
269273 s.data .exclusive = false ;
@@ -276,6 +280,7 @@ namespace hpx::detail {
276280 release_waiters (lk);
277281 break ;
278282 }
283+ s = state.load (std::memory_order_acquire);
279284 }
280285 }
281286
@@ -308,9 +313,9 @@ namespace hpx::detail {
308313
309314 bool try_lock_upgrade ()
310315 {
316+ auto s = state.load (std::memory_order_acquire);
311317 while (true )
312318 {
313- auto s = state.load (std::memory_order_acquire);
314319 if (s.data .exclusive || s.data .exclusive_waiting_blocked ||
315320 s.data .upgrade )
316321 {
@@ -325,15 +330,16 @@ namespace hpx::detail {
325330 {
326331 break ;
327332 }
333+ s = state.load (std::memory_order_acquire);
328334 }
329335 return true ;
330336 }
331337
332338 void unlock_upgrade ()
333339 {
340+ auto s = state.load (std::memory_order_acquire);
334341 while (true )
335342 {
336- auto s = state.load (std::memory_order_acquire);
337343 auto s1 = s;
338344
339345 bool release = false ;
@@ -358,6 +364,7 @@ namespace hpx::detail {
358364 {
359365 break ;
360366 }
367+ s = state.load (std::memory_order_acquire);
361368 }
362369 }
363370
@@ -405,9 +412,9 @@ namespace hpx::detail {
405412
406413 void unlock_and_lock_upgrade ()
407414 {
415+ auto s = state.load (std::memory_order_acquire);
408416 while (true )
409417 {
410- auto s = state.load (std::memory_order_acquire);
411418 auto s1 = s;
412419
413420 s.data .exclusive = false ;
@@ -422,14 +429,15 @@ namespace hpx::detail {
422429 release_waiters (lk);
423430 break ;
424431 }
432+ s = state.load (std::memory_order_acquire);
425433 }
426434 }
427435
428436 void unlock_and_lock_shared ()
429437 {
438+ auto s = state.load (std::memory_order_acquire);
430439 while (true )
431440 {
432- auto s = state.load (std::memory_order_acquire);
433441 auto s1 = s;
434442
435443 s.data .exclusive = false ;
@@ -443,14 +451,15 @@ namespace hpx::detail {
443451 release_waiters (lk);
444452 break ;
445453 }
454+ s = state.load (std::memory_order_acquire);
446455 }
447456 }
448457
449458 bool try_unlock_shared_and_lock ()
450459 {
460+ auto s = state.load (std::memory_order_acquire);
451461 while (true )
452462 {
453- auto s = state.load (std::memory_order_acquire);
454463 if (s.data .exclusive || s.data .exclusive_waiting_blocked ||
455464 s.data .upgrade || s.data .shared_count != 1 )
456465 {
@@ -465,15 +474,16 @@ namespace hpx::detail {
465474 {
466475 break ;
467476 }
477+ s = state.load (std::memory_order_acquire);
468478 }
469479 return true ;
470480 }
471481
472482 void unlock_upgrade_and_lock_shared ()
473483 {
484+ auto s = state.load (std::memory_order_acquire);
474485 while (true )
475486 {
476- auto s = state.load (std::memory_order_acquire);
477487 auto s1 = s;
478488
479489 s.data .exclusive_waiting_blocked = false ;
@@ -486,6 +496,7 @@ namespace hpx::detail {
486496 release_waiters (lk);
487497 break ;
488498 }
499+ s = state.load (std::memory_order_acquire);
489500 }
490501 }
491502
0 commit comments