diff options
author | Hugo Landau <hlandau@openssl.org> | 2023-04-27 16:52:44 +0200 |
---|---|---|
committer | Hugo Landau <hlandau@openssl.org> | 2023-05-12 15:47:14 +0200 |
commit | 008a61a544e16d20595731f614b2fbc1d20f793e (patch) | |
tree | fc1de700f6939738a560b3db66a5b7dff7b2843d | |
parent | QUIC APL: Fix logic of SSL_get_stream_type (diff) | |
download | openssl-008a61a544e16d20595731f614b2fbc1d20f793e.tar.xz openssl-008a61a544e16d20595731f614b2fbc1d20f793e.zip |
REFCOUNT: Add support for querying refcount
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20765)
-rw-r--r-- | include/internal/refcount.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/include/internal/refcount.h b/include/internal/refcount.h index 8674ab3664..fbfe25bd0b 100644 --- a/include/internal/refcount.h +++ b/include/internal/refcount.h @@ -53,6 +53,13 @@ static inline int CRYPTO_DOWN_REF(_Atomic int *val, int *ret, return 1; } +static inline int CRYPTO_GET_REF(_Atomic int *val, int *ret, + ossl_unused void *lock) +{ + *ret = atomic_load_explicit(val, memory_order_relaxed); + return 1; +} + # elif defined(__GNUC__) && defined(__ATOMIC_RELAXED) && __GCC_ATOMIC_INT_LOCK_FREE > 0 # define HAVE_ATOMICS 1 @@ -73,6 +80,13 @@ static __inline__ int CRYPTO_DOWN_REF(int *val, int *ret, __atomic_thread_fence(__ATOMIC_ACQUIRE); return 1; } + +static __inline__ int CRYPTO_GET_REF(int *val, int *ret, ossl_unused void *lock) +{ + *ret = __atomic_load_n(val, __ATOMIC_RELAXED); + return 1; +} + # elif defined(__ICL) && defined(_WIN32) # define HAVE_ATOMICS 1 typedef volatile int CRYPTO_REF_COUNT; @@ -91,6 +105,13 @@ static __inline int CRYPTO_DOWN_REF(volatile int *val, int *ret, return 1; } +static __inline int CRYPTO_GET_REF(volatile int *val, int *ret, + ossl_unused void *lock) +{ + *ret = _InterlockedOr((void *)val, 0); + return 1; +} + # elif defined(_MSC_VER) && _MSC_VER>=1200 # define HAVE_ATOMICS 1 @@ -118,6 +139,14 @@ static __inline int CRYPTO_DOWN_REF(volatile int *val, int *ret, __dmb(_ARM_BARRIER_ISH); return 1; } + +static __inline int CRYPTO_GET_REF(volatile int *val, int *ret, + ossl_unused void *lock) +{ + *ret = _InterlockedOr_nf((void *)val, 0); + return 1; +} + # else # if !defined(_WIN32_WCE) # pragma intrinsic(_InterlockedExchangeAdd) @@ -144,6 +173,14 @@ static __inline int CRYPTO_DOWN_REF(volatile int *val, int *ret, *ret = _InterlockedExchangeAdd(val, -1) - 1; return 1; } + +static __inline int CRYPTO_GET_REF(volatile int *val, int *ret, + ossl_unused void *lock) +{ + *ret = _InterlockedExchangeAdd(val, 0); + return 1; +} + # endif # endif |