Add internal functions to fetch a refcount
authorRichard Levitte <levitte@openssl.org>
Sat, 27 May 2017 20:04:59 +0000 (22:04 +0200)
committerRichard Levitte <levitte@openssl.org>
Sat, 27 May 2017 20:37:19 +0000 (22:37 +0200)
Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3573)

include/internal/refcount.h

index 591561ffeeb7e4a4ebe7ee8f1b005b7c378cf15a..1aea71b2e808356189a767fab54d73527abad718 100644 (file)
 
 typedef _Atomic int CRYPTO_REF_COUNT;
 
+static ossl_inline int CRYPTO_GET_REF(_Atomic int *val, int *ret, void *lock)
+{
+    *ret = atomic_fetch_add_explicit(val, 0, memory_order_relaxed);
+    return 1;
+}
+
 static ossl_inline int CRYPTO_UP_REF(_Atomic int *val, int *ret, void *lock)
 {
     *ret = atomic_fetch_add_explicit(val, 1, memory_order_relaxed) + 1;
@@ -42,6 +48,12 @@ static ossl_inline int CRYPTO_DOWN_REF(_Atomic int *val, int *ret, void *lock)
 
 typedef int CRYPTO_REF_COUNT;
 
+static ossl_inline int CRYPTO_GET_REF(_Atomic int *val, int *ret, void *lock)
+{
+    *ret = __atomic_fetch_add(val, 0, __ATOMIC_RELAXED);
+    return 1;
+}
+
 static ossl_inline int CRYPTO_UP_REF(int *val, int *ret, void *lock)
 {
     *ret = __atomic_fetch_add(val, 1, __ATOMIC_RELAXED) + 1;
@@ -60,6 +72,7 @@ static ossl_inline int CRYPTO_DOWN_REF(int *val, int *ret, void *lock)
 
 typedef int CRYPTO_REF_COUNT;
 
+# define CRYPTO_GET_REF(val, ret, lock) CRYPTO_atomic_add(val, 0, ret, lock)
 # define CRYPTO_UP_REF(val, ret, lock) CRYPTO_atomic_add(val, 1, ret, lock)
 # define CRYPTO_DOWN_REF(val, ret, lock) CRYPTO_atomic_add(val, -1, ret, lock)