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 ...@@ -572,7 +572,7 @@ struct rw_lock_t
std::atomic<int32_t> lock_word; std::atomic<int32_t> lock_word;
/** 1: there are waiters */ /** 1: there are waiters */
int32_t waiters; std::atomic<int32_t> waiters;
/** number of granted SX locks. */ /** number of granted SX locks. */
volatile ulint sx_recursive; volatile ulint sx_recursive;
......
...@@ -414,10 +414,8 @@ rw_lock_x_unlock_func( ...@@ -414,10 +414,8 @@ rw_lock_x_unlock_func(
We need to signal read/write waiters. We need to signal read/write waiters.
We do not need to signal wait_ex waiters, since they cannot We do not need to signal wait_ex waiters, since they cannot
exist when there is a writer. */ exist when there is a writer. */
if (my_atomic_load32_explicit(&lock->waiters, if (lock->waiters.load(std::memory_order_relaxed)) {
MY_MEMORY_ORDER_RELAXED)) { lock->waiters.store(0, std::memory_order_relaxed);
my_atomic_store32_explicit(&lock->waiters, 0,
MY_MEMORY_ORDER_RELAXED);
os_event_set(lock->event); os_event_set(lock->event);
sync_array_object_signalled(); sync_array_object_signalled();
} }
...@@ -474,10 +472,8 @@ rw_lock_sx_unlock_func( ...@@ -474,10 +472,8 @@ rw_lock_sx_unlock_func(
waiters. We do not need to signal wait_ex waiters, waiters. We do not need to signal wait_ex waiters,
since they cannot exist when there is an sx-lock since they cannot exist when there is an sx-lock
holder. */ holder. */
if (my_atomic_load32_explicit(&lock->waiters, if (lock->waiters.load(std::memory_order_relaxed)) {
MY_MEMORY_ORDER_RELAXED)) { lock->waiters.store(0, std::memory_order_relaxed);
my_atomic_store32_explicit(&lock->waiters, 0,
MY_MEMORY_ORDER_RELAXED);
os_event_set(lock->event); os_event_set(lock->event);
sync_array_object_signalled(); sync_array_object_signalled();
} }
......
...@@ -1977,8 +1977,8 @@ row_merge_read_clustered_index( ...@@ -1977,8 +1977,8 @@ row_merge_read_clustered_index(
goto scan_next; goto scan_next;
} }
if (my_atomic_load32_explicit(&clust_index->lock.waiters, if (clust_index->lock.waiters.load(
MY_MEMORY_ORDER_RELAXED)) { std::memory_order_relaxed)) {
/* There are waiters on the clustered /* There are waiters on the clustered
index tree lock, likely the purge index tree lock, likely the purge
thread. Store and restore the cursor thread. Store and restore the cursor
......
...@@ -591,7 +591,7 @@ sync_array_cell_print( ...@@ -591,7 +591,7 @@ sync_array_cell_print(
#endif #endif
"\n", "\n",
rw_lock_get_reader_count(rwlock), 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), rwlock->lock_word.load(std::memory_order_relaxed),
innobase_basename(rwlock->last_x_file_name), innobase_basename(rwlock->last_x_file_name),
rwlock->last_x_line rwlock->last_x_line
...@@ -1379,7 +1379,7 @@ sync_arr_fill_sys_semphore_waits_table( ...@@ -1379,7 +1379,7 @@ sync_arr_fill_sys_semphore_waits_table(
//fields[SYS_SEMAPHORE_WAITS_HOLDER_LINE]->set_notnull(); //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_READERS], rw_lock_get_reader_count(rwlock)));
OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_WAITERS_FLAG], 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], OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_LOCK_WORD],
rwlock->lock_word.load(std::memory_order_relaxed))); 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))); 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( ...@@ -206,7 +206,7 @@ rw_lock_create_func(
created, then the following call initializes the sync system. */ created, then the following call initializes the sync system. */
lock->lock_word.store(X_LOCK_DECR, std::memory_order_relaxed); 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->sx_recursive = 0;
lock->writer_thread= 0; lock->writer_thread= 0;
...@@ -345,7 +345,7 @@ rw_lock_s_lock_spin( ...@@ -345,7 +345,7 @@ rw_lock_s_lock_spin(
/* Set waiters before checking lock_word to ensure wake-up /* Set waiters before checking lock_word to ensure wake-up
signal is sent. This may lead to some unnecessary signals. */ 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)) { if (rw_lock_s_lock_low(lock, pass, file_name, line)) {
...@@ -713,7 +713,7 @@ rw_lock_x_lock_func( ...@@ -713,7 +713,7 @@ rw_lock_x_lock_func(
/* Waiters must be set before checking lock_word, to ensure signal /* Waiters must be set before checking lock_word, to ensure signal
is sent. This could lead to a few unnecessary wake-up signals. */ 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)) { if (rw_lock_x_lock_low(lock, pass, file_name, line)) {
sync_array_free_cell(sync_arr, cell); sync_array_free_cell(sync_arr, cell);
...@@ -813,7 +813,7 @@ rw_lock_sx_lock_func( ...@@ -813,7 +813,7 @@ rw_lock_sx_lock_func(
/* Waiters must be set before checking lock_word, to ensure signal /* Waiters must be set before checking lock_word, to ensure signal
is sent. This could lead to a few unnecessary wake-up signals. */ 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)) { if (rw_lock_sx_lock_low(lock, pass, file_name, line)) {
...@@ -859,8 +859,7 @@ rw_lock_validate( ...@@ -859,8 +859,7 @@ rw_lock_validate(
lock_word = lock->lock_word.load(std::memory_order_relaxed); lock_word = lock->lock_word.load(std::memory_order_relaxed);
ut_ad(lock->magic_n == RW_LOCK_MAGIC_N); ut_ad(lock->magic_n == RW_LOCK_MAGIC_N);
ut_ad(my_atomic_load32_explicit(const_cast<int32_t*>(&lock->waiters), ut_ad(lock->waiters.load(std::memory_order_relaxed) < 2);
MY_MEMORY_ORDER_RELAXED) < 2);
ut_ad(lock_word > -(2 * X_LOCK_DECR)); ut_ad(lock_word > -(2 * X_LOCK_DECR));
ut_ad(lock_word <= X_LOCK_DECR); ut_ad(lock_word <= X_LOCK_DECR);
...@@ -1093,7 +1092,7 @@ rw_lock_list_print_info( ...@@ -1093,7 +1092,7 @@ rw_lock_list_print_info(
fprintf(file, "RW-LOCK: %p ", (void*) lock); 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); fprintf(file, " (%d waiters)\n", waiters);
} else { } else {
putc('\n', file); 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