@@ -380,7 +380,7 @@ struct TTASEventMutex {
380
380
~TTASEventMutex ()
381
381
UNIV_NOTHROW
382
382
{
383
- ut_ad (m_lock_word == MUTEX_STATE_UNLOCKED);
383
+ ut_ad (state () == MUTEX_STATE_UNLOCKED);
384
384
}
385
385
386
386
/* * Called when the mutex is "created". Note: Not from the constructor
@@ -389,7 +389,7 @@ struct TTASEventMutex {
389
389
void init (latch_id_t id, const char *, uint32_t ) UNIV_NOTHROW
390
390
{
391
391
ut_a (m_event == 0 );
392
- ut_a (m_lock_word == MUTEX_STATE_UNLOCKED);
392
+ ut_ad ( state () == MUTEX_STATE_UNLOCKED);
393
393
394
394
m_event = os_event_create (sync_latch_get_name (id));
395
395
}
@@ -400,7 +400,7 @@ struct TTASEventMutex {
400
400
void destroy ()
401
401
UNIV_NOTHROW
402
402
{
403
- ut_ad (m_lock_word == MUTEX_STATE_UNLOCKED);
403
+ ut_ad (state () == MUTEX_STATE_UNLOCKED);
404
404
405
405
/* We have to free the event before InnoDB shuts down. */
406
406
os_event_destroy (m_event);
@@ -412,20 +412,20 @@ struct TTASEventMutex {
412
412
bool try_lock ()
413
413
UNIV_NOTHROW
414
414
{
415
- int32 oldval = MUTEX_STATE_UNLOCKED;
416
- return (my_atomic_cas32_strong_explicit (&m_lock_word, &oldval,
417
- MUTEX_STATE_LOCKED,
418
- MY_MEMORY_ORDER_ACQUIRE,
419
- MY_MEMORY_ORDER_RELAXED));
415
+ uint32_t oldval = MUTEX_STATE_UNLOCKED;
416
+ return m_lock_word.compare_exchange_strong (
417
+ oldval,
418
+ MUTEX_STATE_LOCKED,
419
+ std::memory_order_acquire,
420
+ std::memory_order_relaxed);
420
421
}
421
422
422
423
/* * Release the mutex. */
423
424
void exit ()
424
425
UNIV_NOTHROW
425
426
{
426
- if (my_atomic_fas32_explicit (&m_lock_word,
427
- MUTEX_STATE_UNLOCKED,
428
- MY_MEMORY_ORDER_RELEASE)
427
+ if (m_lock_word.exchange (MUTEX_STATE_UNLOCKED,
428
+ std::memory_order_release)
429
429
== MUTEX_STATE_WAITERS) {
430
430
os_event_set (m_event);
431
431
sync_array_object_signalled ();
@@ -463,11 +463,12 @@ struct TTASEventMutex {
463
463
: SYNC_MUTEX,
464
464
filename, line, &cell);
465
465
466
- int32 oldval = MUTEX_STATE_LOCKED;
467
- my_atomic_cas32_strong_explicit (&m_lock_word, &oldval,
468
- MUTEX_STATE_WAITERS,
469
- MY_MEMORY_ORDER_RELAXED,
470
- MY_MEMORY_ORDER_RELAXED);
466
+ uint32_t oldval = MUTEX_STATE_LOCKED;
467
+ m_lock_word.compare_exchange_strong (
468
+ oldval,
469
+ MUTEX_STATE_WAITERS,
470
+ std::memory_order_relaxed,
471
+ std::memory_order_relaxed);
471
472
472
473
if (oldval == MUTEX_STATE_UNLOCKED) {
473
474
sync_array_free_cell (sync_arr, cell);
@@ -486,9 +487,7 @@ struct TTASEventMutex {
486
487
int32 state () const
487
488
UNIV_NOTHROW
488
489
{
489
- return (my_atomic_load32_explicit (const_cast <int32*>
490
- (&m_lock_word),
491
- MY_MEMORY_ORDER_RELAXED));
490
+ return m_lock_word.load (std::memory_order_relaxed);
492
491
}
493
492
494
493
/* * The event that the mutex will wait in sync0arr.cc
@@ -518,9 +517,8 @@ struct TTASEventMutex {
518
517
TTASEventMutex (const TTASEventMutex&);
519
518
TTASEventMutex& operator =(const TTASEventMutex&);
520
519
521
- /* * lock_word is the target of the atomic test-and-set instruction
522
- when atomic operations are enabled. */
523
- int32 m_lock_word;
520
+ /* * mutex state */
521
+ std::atomic<uint32_t > m_lock_word;
524
522
525
523
/* * Used by sync0arr.cc for the wait queue */
526
524
os_event_t m_event;
0 commit comments