Commit e60dc209 authored by Sergey Vojtovich's avatar Sergey Vojtovich

MDEV-17441 - InnoDB transition to C++11 atomics

Almost trivial rw_lock_t::waiters transition. Since C++11 doesn't
seem to allow mixed (atomic and non-atomic) access to atomic variables,
we have to perform atomic initialisation.
parent 9581c4a8
......@@ -572,7 +572,7 @@ struct rw_lock_t
std::atomic<int32_t> lock_word;
/** 1: there are waiters */
int32_t waiters;
std::atomic<int32_t> waiters;
/** number of granted SX locks. */
volatile ulint sx_recursive;
......
......@@ -414,10 +414,8 @@ rw_lock_x_unlock_func(
We need to signal read/write waiters.
We do not need to signal wait_ex waiters, since they cannot
exist when there is a writer. */
if (my_atomic_load32_explicit(&lock->waiters,
MY_MEMORY_ORDER_RELAXED)) {
my_atomic_store32_explicit(&lock->waiters, 0,
MY_MEMORY_ORDER_RELAXED);
if (lock->waiters.load(std::memory_order_relaxed)) {
lock->waiters.store(0, std::memory_order_relaxed);
os_event_set(lock->event);
sync_array_object_signalled();
}
......@@ -474,10 +472,8 @@ rw_lock_sx_unlock_func(
waiters. We do not need to signal wait_ex waiters,
since they cannot exist when there is an sx-lock
holder. */
if (my_atomic_load32_explicit(&lock->waiters,
MY_MEMORY_ORDER_RELAXED)) {
my_atomic_store32_explicit(&lock->waiters, 0,
MY_MEMORY_ORDER_RELAXED);
if (lock->waiters.load(std::memory_order_relaxed)) {
lock->waiters.store(0, std::memory_order_relaxed);
os_event_set(lock->event);
sync_array_object_signalled();
}
......
......@@ -1977,8 +1977,8 @@ row_merge_read_clustered_index(
goto scan_next;
}
if (my_atomic_load32_explicit(&clust_index->lock.waiters,
MY_MEMORY_ORDER_RELAXED)) {
if (clust_index->lock.waiters.load(
std::memory_order_relaxed)) {
/* There are waiters on the clustered
index tree lock, likely the purge
thread. Store and restore the cursor
......
......@@ -591,7 +591,7 @@ sync_array_cell_print(
#endif
"\n",
rw_lock_get_reader_count(rwlock),
my_atomic_load32_explicit(&rwlock->waiters, MY_MEMORY_ORDER_RELAXED),
rwlock->waiters.load(std::memory_order_relaxed),
rwlock->lock_word.load(std::memory_order_relaxed),
innobase_basename(rwlock->last_x_file_name),
rwlock->last_x_line
......@@ -1379,7 +1379,7 @@ sync_arr_fill_sys_semphore_waits_table(
//fields[SYS_SEMAPHORE_WAITS_HOLDER_LINE]->set_notnull();
OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_READERS], rw_lock_get_reader_count(rwlock)));
OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_WAITERS_FLAG],
my_atomic_load32_explicit(&rwlock->waiters, MY_MEMORY_ORDER_RELAXED)));
rwlock->waiters.load(std::memory_order_relaxed)));
OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_LOCK_WORD],
rwlock->lock_word.load(std::memory_order_relaxed)));
OK(field_store_string(fields[SYS_SEMAPHORE_WAITS_LAST_WRITER_FILE], innobase_basename(rwlock->last_x_file_name)));
......
......@@ -206,7 +206,7 @@ rw_lock_create_func(
created, then the following call initializes the sync system. */
lock->lock_word.store(X_LOCK_DECR, std::memory_order_relaxed);
lock->waiters = 0;
lock->waiters.store(0, std::memory_order_relaxed);
lock->sx_recursive = 0;
lock->writer_thread= 0;
......@@ -345,7 +345,7 @@ rw_lock_s_lock_spin(
/* Set waiters before checking lock_word to ensure wake-up
signal is sent. This may lead to some unnecessary signals. */
my_atomic_fas32_explicit(&lock->waiters, 1, MY_MEMORY_ORDER_ACQUIRE);
lock->waiters.exchange(1, std::memory_order_acquire);
if (rw_lock_s_lock_low(lock, pass, file_name, line)) {
......@@ -713,7 +713,7 @@ rw_lock_x_lock_func(
/* Waiters must be set before checking lock_word, to ensure signal
is sent. This could lead to a few unnecessary wake-up signals. */
my_atomic_fas32_explicit(&lock->waiters, 1, MY_MEMORY_ORDER_ACQUIRE);
lock->waiters.exchange(1, std::memory_order_acquire);
if (rw_lock_x_lock_low(lock, pass, file_name, line)) {
sync_array_free_cell(sync_arr, cell);
......@@ -813,7 +813,7 @@ rw_lock_sx_lock_func(
/* Waiters must be set before checking lock_word, to ensure signal
is sent. This could lead to a few unnecessary wake-up signals. */
my_atomic_fas32_explicit(&lock->waiters, 1, MY_MEMORY_ORDER_ACQUIRE);
lock->waiters.exchange(1, std::memory_order_acquire);
if (rw_lock_sx_lock_low(lock, pass, file_name, line)) {
......@@ -859,8 +859,7 @@ rw_lock_validate(
lock_word = lock->lock_word.load(std::memory_order_relaxed);
ut_ad(lock->magic_n == RW_LOCK_MAGIC_N);
ut_ad(my_atomic_load32_explicit(const_cast<int32_t*>(&lock->waiters),
MY_MEMORY_ORDER_RELAXED) < 2);
ut_ad(lock->waiters.load(std::memory_order_relaxed) < 2);
ut_ad(lock_word > -(2 * X_LOCK_DECR));
ut_ad(lock_word <= X_LOCK_DECR);
......@@ -1093,7 +1092,7 @@ rw_lock_list_print_info(
fprintf(file, "RW-LOCK: %p ", (void*) lock);
if (int32_t waiters= my_atomic_load32_explicit(const_cast<int32_t*>(&lock->waiters), MY_MEMORY_ORDER_RELAXED)) {
if (int32_t waiters= lock->waiters.load(std::memory_order_relaxed)) {
fprintf(file, " (%d waiters)\n", waiters);
} else {
putc('\n', file);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment