Skip to content
Permalink
Browse files
fix data races
  • Loading branch information
kevgs authored and Sergey Vojtovich committed Oct 12, 2017
1 parent 7d2a778 commit f3ad3bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
@@ -393,17 +393,21 @@ rw_lock_x_unlock_func(
#endif /* UNIV_DEBUG */
rw_lock_t* lock) /*!< in/out: rw-lock */
{
ut_ad(lock->lock_word == 0 || lock->lock_word == -X_LOCK_HALF_DECR
|| lock->lock_word <= -X_LOCK_DECR);
lint lock_word;
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. */
lock->writer_thread = 0;
}

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 */
/* atomic increment is needed, because it is last */
if (my_atomic_addlint(&lock->lock_word, X_LOCK_DECR) <= -X_LOCK_DECR) {
@@ -421,13 +425,13 @@ rw_lock_x_unlock_func(
os_event_set(lock->event);
sync_array_object_signalled();
}
} else if (lock->lock_word == -X_LOCK_DECR
|| lock->lock_word == -(X_LOCK_DECR + X_LOCK_HALF_DECR)) {
} else if (lock_word == -X_LOCK_DECR
|| lock_word == -(X_LOCK_DECR + X_LOCK_HALF_DECR)) {
/* There are 2 x-locks */
lock->lock_word += X_LOCK_DECR;
} else {
/* 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;
}

@@ -310,7 +310,9 @@ rw_lock_s_lock_spin(

/* Spin waiting for the writer field to become free */
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) {
ut_delay(ut_rnd_interval(0, srv_spin_wait_delay));
}

0 comments on commit f3ad3bb

Please sign in to comment.