Skip to content

Commit

Permalink
REFCOUNT: Add support for querying refcount
Browse files Browse the repository at this point in the history
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #20765)
  • Loading branch information
hlandau committed May 12, 2023
1 parent 59c5c01 commit 008a61a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions include/internal/refcount.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 008a61a

Please sign in to comment.