summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Kosov <claprix@yandex.ru>2017-10-09 22:55:05 +0300
committerSergey Vojtovich <svoj@mariadb.org>2017-10-09 23:55:05 +0400
commitbbfd18c69102c2831f03f7d9dc5b67bd8556b09a (patch)
tree318f62ab3e6b323ea99a53174179c6f23f2cb846
parentb3027d4065538425f4a8e71fef1227ef41d10d05 (diff)
downloadmariadb-git-bbfd18c69102c2831f03f7d9dc5b67bd8556b09a.tar.gz
fix unsynchronized read (#463)
* fix unsynchronized read * use relaxed atomic instead of seq_cst
-rw-r--r--include/my_atomic.h2
-rw-r--r--storage/innobase/include/sync0rw.ic3
-rw-r--r--storage/innobase/include/sync0types.h2
3 files changed, 6 insertions, 1 deletions
diff --git a/include/my_atomic.h b/include/my_atomic.h
index 5860426304e..bcb6005a8c2 100644
--- a/include/my_atomic.h
+++ b/include/my_atomic.h
@@ -235,12 +235,14 @@ make_atomic_store(ptr)
#if SIZEOF_LONG == 4
#define my_atomic_addlong(A,B) my_atomic_add32((int32*) (A), (B))
#define my_atomic_loadlong(A) my_atomic_load32((int32*) (A))
+#define my_atomic_loadlong_explicit(A,O) my_atomic_load32_explicit((int32*) (A), (O))
#define my_atomic_storelong(A,B) my_atomic_store32((int32*) (A), (B))
#define my_atomic_faslong(A,B) my_atomic_fas32((int32*) (A), (B))
#define my_atomic_caslong(A,B,C) my_atomic_cas32((int32*) (A), (int32*) (B), (C))
#else
#define my_atomic_addlong(A,B) my_atomic_add64((int64*) (A), (B))
#define my_atomic_loadlong(A) my_atomic_load64((int64*) (A))
+#define my_atomic_loadlong_explicit(A,O) my_atomic_load64_explicit((int64*) (A), (O))
#define my_atomic_storelong(A,B) my_atomic_store64((int64*) (A), (B))
#define my_atomic_faslong(A,B) my_atomic_fas64((int64*) (A), (B))
#define my_atomic_caslong(A,B,C) my_atomic_cas64((int64*) (A), (int64*) (B), (C))
diff --git a/storage/innobase/include/sync0rw.ic b/storage/innobase/include/sync0rw.ic
index 21872cc8bee..21d12b744a9 100644
--- a/storage/innobase/include/sync0rw.ic
+++ b/storage/innobase/include/sync0rw.ic
@@ -213,7 +213,8 @@ rw_lock_lock_word_decr(
{
lint local_lock_word;
- local_lock_word = lock->lock_word;
+ local_lock_word = my_atomic_loadlint_explicit(&lock->lock_word,
+ MY_MEMORY_ORDER_RELAXED);
while (local_lock_word > threshold) {
if (my_atomic_caslint(&lock->lock_word,
&local_lock_word,
diff --git a/storage/innobase/include/sync0types.h b/storage/innobase/include/sync0types.h
index 0c1c9adee45..1f8e245569e 100644
--- a/storage/innobase/include/sync0types.h
+++ b/storage/innobase/include/sync0types.h
@@ -1163,11 +1163,13 @@ enum rw_lock_flag_t {
#ifdef _WIN64
#define my_atomic_addlint(A,B) my_atomic_add64((int64*) (A), (B))
#define my_atomic_loadlint(A) my_atomic_load64((int64*) (A))
+#define my_atomic_loadlint_explicit(A,O) my_atomic_load64_explicit((int64*) (A), (O))
#define my_atomic_storelint(A,B) my_atomic_store64((int64*) (A), (B))
#define my_atomic_caslint(A,B,C) my_atomic_cas64((int64*) (A), (int64*) (B), (C))
#else
#define my_atomic_addlint my_atomic_addlong
#define my_atomic_loadlint my_atomic_loadlong
+#define my_atomic_loadlint_explicit my_atomic_loadlong_explicit
#define my_atomic_storelint my_atomic_storelong
#define my_atomic_caslint my_atomic_caslong
#endif