If not, fall back to our own code, using the given mutex
Reviewed-by: Andy Polyakov <appro@openssl.org>
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;
if (!CRYPTO_THREAD_unlock(lock))
return 0;
-# endif
return 1;
}