summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2016-08-24 09:14:44 +0200
committerMatt Caswell <matt@openssl.org>2016-08-24 14:37:48 +0100
commit1beca67688189f6542c7d08233c28e8fab73dba7 (patch)
treed281e257a9cc10f98feb7cbc749a0465e4e4cb6e
parent11fc6c761165283f5aed9aed5edd65c1bb963e79 (diff)
downloadopenssl-new-1beca67688189f6542c7d08233c28e8fab73dba7.tar.gz
CRYPTO_atomic_add(): check that the object is lock free
If not, fall back to our own code, using the given mutex Reviewed-by: Andy Polyakov <appro@openssl.org>
-rw-r--r--crypto/threads_pthread.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/crypto/threads_pthread.c b/crypto/threads_pthread.c
index 9f4ae76bf8..5cc48afb16 100644
--- a/crypto/threads_pthread.c
+++ b/crypto/threads_pthread.c
@@ -110,8 +110,11 @@ 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)
{
# if defined(__GNUC__) && defined(__ATOMIC_ACQ_REL)
- *ret = __atomic_add_fetch(val, amount, __ATOMIC_ACQ_REL);
-# else
+ if (__atomic_is_lock_free(sizeof(*val), val)) {
+ *ret = __atomic_add_fetch(val, amount, __ATOMIC_ACQ_REL);
+ return 1;
+ }
+# endif
if (!CRYPTO_THREAD_write_lock(lock))
return 0;
@@ -120,7 +123,6 @@ int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)
if (!CRYPTO_THREAD_unlock(lock))
return 0;
-# endif
return 1;
}