CRYPTO_atomic_add(): use acquire release memory order rather than relaxed
authorRichard Levitte <levitte@openssl.org>
Wed, 24 Aug 2016 10:01:39 +0000 (12:01 +0200)
committerMatt Caswell <matt@openssl.org>
Wed, 24 Aug 2016 13:37:40 +0000 (14:37 +0100)
For increments, the relaxed model is fine.  For decrements, it's
recommended to use the acquire release model.  We therefore go for the
latter.

Reviewed-by: Andy Polyakov <appro@openssl.org>
crypto/threads_pthread.c

index 72ea83892bbe66ca7fe725d4c006d74c1c385d55..9f4ae76bf85d61ec7997841c09049b6c8f5f8189 100644 (file)
@@ -109,8 +109,8 @@ int CRYPTO_THREAD_compare_id(CRYPTO_THREAD_ID a, CRYPTO_THREAD_ID b)
 
 int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)
 {
 
 int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)
 {
-# if defined(__GNUC__) && defined(__ATOMIC_RELAXED)
-    *ret = __atomic_add_fetch(val, amount, __ATOMIC_RELAXED);
+# if defined(__GNUC__) && defined(__ATOMIC_ACQ_REL)
+    *ret = __atomic_add_fetch(val, amount, __ATOMIC_ACQ_REL);
 # else
     if (!CRYPTO_THREAD_write_lock(lock))
         return 0;
 # else
     if (!CRYPTO_THREAD_write_lock(lock))
         return 0;