Commit f3ad3bbe authored by Eugene Kosov's avatar Eugene Kosov Committed by Sergey Vojtovich

fix data races

parent 7d2a7782
...@@ -393,17 +393,21 @@ rw_lock_x_unlock_func( ...@@ -393,17 +393,21 @@ rw_lock_x_unlock_func(
#endif /* UNIV_DEBUG */ #endif /* UNIV_DEBUG */
rw_lock_t* lock) /*!< in/out: rw-lock */ rw_lock_t* lock) /*!< in/out: rw-lock */
{ {
ut_ad(lock->lock_word == 0 || lock->lock_word == -X_LOCK_HALF_DECR lint lock_word;
|| lock->lock_word <= -X_LOCK_DECR); lock_word = my_atomic_loadlint_explicit(&lock->lock_word,
MY_MEMORY_ORDER_RELAXED);
if (lock->lock_word == 0) { ut_ad(lock_word == 0 || lock_word == -X_LOCK_HALF_DECR
|| lock_word <= -X_LOCK_DECR);
if (lock_word == 0) {
/* Last caller in a possible recursive chain. */ /* Last caller in a possible recursive chain. */
lock->writer_thread = 0; lock->writer_thread = 0;
} }
ut_d(rw_lock_remove_debug_info(lock, pass, RW_LOCK_X)); ut_d(rw_lock_remove_debug_info(lock, pass, RW_LOCK_X));
if (lock->lock_word == 0 || lock->lock_word == -X_LOCK_HALF_DECR) { if (lock_word == 0 || lock_word == -X_LOCK_HALF_DECR) {
/* There is 1 x-lock */ /* There is 1 x-lock */
/* atomic increment is needed, because it is last */ /* atomic increment is needed, because it is last */
if (my_atomic_addlint(&lock->lock_word, X_LOCK_DECR) <= -X_LOCK_DECR) { if (my_atomic_addlint(&lock->lock_word, X_LOCK_DECR) <= -X_LOCK_DECR) {
...@@ -421,13 +425,13 @@ rw_lock_x_unlock_func( ...@@ -421,13 +425,13 @@ rw_lock_x_unlock_func(
os_event_set(lock->event); os_event_set(lock->event);
sync_array_object_signalled(); sync_array_object_signalled();
} }
} else if (lock->lock_word == -X_LOCK_DECR } else if (lock_word == -X_LOCK_DECR
|| lock->lock_word == -(X_LOCK_DECR + X_LOCK_HALF_DECR)) { || lock_word == -(X_LOCK_DECR + X_LOCK_HALF_DECR)) {
/* There are 2 x-locks */ /* There are 2 x-locks */
lock->lock_word += X_LOCK_DECR; lock->lock_word += X_LOCK_DECR;
} else { } else {
/* There are more than 2 x-locks. */ /* There are more than 2 x-locks. */
ut_ad(lock->lock_word < -X_LOCK_DECR); ut_ad(lock_word < -X_LOCK_DECR);
lock->lock_word += 1; lock->lock_word += 1;
} }
......
...@@ -310,7 +310,9 @@ rw_lock_s_lock_spin( ...@@ -310,7 +310,9 @@ rw_lock_s_lock_spin(
/* Spin waiting for the writer field to become free */ /* Spin waiting for the writer field to become free */
HMT_low(); HMT_low();
while (i < srv_n_spin_wait_rounds && lock->lock_word <= 0) { while (i < srv_n_spin_wait_rounds &&
my_atomic_loadlint_explicit(&lock->lock_word,
MY_MEMORY_ORDER_RELAXED) <= 0) {
if (srv_spin_wait_delay) { if (srv_spin_wait_delay) {
ut_delay(ut_rnd_interval(0, srv_spin_wait_delay)); ut_delay(ut_rnd_interval(0, srv_spin_wait_delay));
} }
......
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