fix unsynchronized read (#463)

* fix unsynchronized read

* use relaxed atomic instead of seq_cst
This commit is contained in:
Eugene Kosov 2017-10-09 22:55:05 +03:00 committed by Sergey Vojtovich
parent b3027d4065
commit bbfd18c691
3 changed files with 6 additions and 1 deletions

View file

@ -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))

View file

@ -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,

View file

@ -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