version 1.3, 2019/01/09 16:55:15 |
version 1.4, 2020/05/24 19:46:26 |
Line 42 typedef atomic_uint_fast32_t isc_refcoun |
|
Line 42 typedef atomic_uint_fast32_t isc_refcoun |
|
* |
* |
* \warning No memory barrier are being imposed here. |
* \warning No memory barrier are being imposed here. |
*/ |
*/ |
#define isc_refcount_init(target, value) \ |
#define isc_refcount_init(target, value) atomic_init(target, value) |
atomic_init(target, value) |
|
|
|
/** \def isc_refcount_current(ref) |
/** \def isc_refcount_current(ref) |
* \brief Returns current number of references. |
* \brief Returns current number of references. |
* \param[in] ref pointer to reference counter. |
* \param[in] ref pointer to reference counter. |
* \returns current value of reference counter. |
* \returns current value of reference counter. |
* |
* |
* Undo implict promotion to 64 bits in our Windows implementation of |
* Undo implicit promotion to 64 bits in our Windows implementation of |
* atomic_load_explicit() by casting to uint_fast32_t. |
* atomic_load_explicit() by casting to uint_fast32_t. |
*/ |
*/ |
|
|
#define isc_refcount_current(target) \ |
#define isc_refcount_current(target) (uint_fast32_t) atomic_load_acquire(target) |
(uint_fast32_t)atomic_load_explicit(target, memory_order_acquire) |
|
|
|
/** \def isc_refcount_destroy(ref) |
/** \def isc_refcount_destroy(ref) |
* \brief a destructor that makes sure that all references were cleared. |
* \brief a destructor that makes sure that all references were cleared. |
* \param[in] ref pointer to reference counter. |
* \param[in] ref pointer to reference counter. |
* \returns nothing. |
* \returns nothing. |
*/ |
*/ |
#define isc_refcount_destroy(target) \ |
#define isc_refcount_destroy(target) \ |
ISC_REQUIRE(isc_refcount_current(target) == 0) |
ISC_REQUIRE(isc_refcount_current(target) == 0) |
|
|
/** \def isc_refcount_increment0(ref) |
/** \def isc_refcount_increment0(ref) |
Line 70 typedef atomic_uint_fast32_t isc_refcoun |
|
Line 68 typedef atomic_uint_fast32_t isc_refcoun |
|
* \param[in] ref pointer to reference counter. |
* \param[in] ref pointer to reference counter. |
* \returns previous value of reference counter. |
* \returns previous value of reference counter. |
*/ |
*/ |
#define isc_refcount_increment0(target) \ |
#if _MSC_VER |
isc_refcount_increment(target) |
static inline uint_fast32_t |
|
isc_refcount_increment0(isc_refcount_t *target) { |
|
uint_fast32_t __v; |
|
__v = (uint_fast32_t)atomic_fetch_add_relaxed(target, 1); |
|
INSIST(__v < UINT32_MAX); |
|
return (__v); |
|
} |
|
#else /* _MSC_VER */ |
|
#define isc_refcount_increment0(target) \ |
|
({ \ |
|
/* cppcheck-suppress shadowVariable */ \ |
|
uint_fast32_t __v; \ |
|
__v = atomic_fetch_add_relaxed(target, 1); \ |
|
INSIST(__v < UINT32_MAX); \ |
|
__v; \ |
|
}) |
|
#endif /* _MSC_VER */ |
|
|
/** \def isc_refcount_increment(ref) |
/** \def isc_refcount_increment(ref) |
* \brief increases reference counter by 1. |
* \brief increases reference counter by 1. |
* \param[in] ref pointer to reference counter. |
* \param[in] ref pointer to reference counter. |
* \returns previous value of reference counter. |
* \returns previous value of reference counter. |
*/ |
*/ |
#define isc_refcount_increment(target) \ |
#if _MSC_VER |
atomic_fetch_add_explicit(target, 1, memory_order_relaxed) |
static inline uint_fast32_t |
|
isc_refcount_increment(isc_refcount_t *target) { |
|
uint_fast32_t __v; |
|
__v = (uint_fast32_t)atomic_fetch_add_relaxed(target, 1); |
|
INSIST(__v > 0 && __v < UINT32_MAX); |
|
return (__v); |
|
} |
|
#else /* _MSC_VER */ |
|
#define isc_refcount_increment(target) \ |
|
({ \ |
|
/* cppcheck-suppress shadowVariable */ \ |
|
uint_fast32_t __v; \ |
|
__v = atomic_fetch_add_relaxed(target, 1); \ |
|
INSIST(__v > 0 && __v < UINT32_MAX); \ |
|
__v; \ |
|
}) |
|
#endif /* _MSC_VER */ |
|
|
/** \def isc_refcount_decrement(ref) |
/** \def isc_refcount_decrement(ref) |
* \brief decreases reference counter by 1. |
* \brief decreases reference counter by 1. |
* \param[in] ref pointer to reference counter. |
* \param[in] ref pointer to reference counter. |
* \returns previous value of reference counter. |
* \returns previous value of reference counter. |
*/ |
*/ |
#define isc_refcount_decrement(target) \ |
#if _MSC_VER |
atomic_fetch_sub_explicit(target, 1, memory_order_release) |
static inline uint_fast32_t |
|
isc_refcount_decrement(isc_refcount_t *target) { |
|
uint_fast32_t __v; |
|
__v = (uint_fast32_t)atomic_fetch_sub_release(target, 1); |
|
INSIST(__v > 0); |
|
return (__v); |
|
} |
|
#else /* _MSC_VER */ |
|
#define isc_refcount_decrement(target) \ |
|
({ \ |
|
/* cppcheck-suppress shadowVariable */ \ |
|
uint_fast32_t __v; \ |
|
__v = atomic_fetch_sub_release(target, 1); \ |
|
INSIST(__v > 0); \ |
|
__v; \ |
|
}) |
|
#endif /* _MSC_VER */ |
|
|
ISC_LANG_ENDDECLS |
ISC_LANG_ENDDECLS |