]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
When compiling with MSVC, use inline functions for isc_refcount_increment/decrement
authorOndřej Surý <ondrej@sury.org>
Wed, 9 Oct 2019 06:20:16 +0000 (08:20 +0200)
committerOndřej Surý <ondrej@sury.org>
Tue, 14 Jan 2020 12:12:13 +0000 (13:12 +0100)
lib/isc/include/isc/refcount.h

index 0b9640ab022d5135358cc0ca97a80c9dd81415d6..32ac95a76e9e5daad7456c889fd16973cb01ef24 100644 (file)
@@ -68,6 +68,15 @@ typedef atomic_uint_fast32_t isc_refcount_t;
  *  \param[in] ref pointer to reference counter.
  *  \returns previous value of reference counter.
  */
+#if _MSC_VER
+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 */                  \
@@ -76,12 +85,22 @@ typedef atomic_uint_fast32_t isc_refcount_t;
                INSIST(__v < UINT32_MAX);                               \
                __v;                                                    \
        })
+#endif /* _MSC_VER */
 
 /** \def isc_refcount_increment(ref)
  *  \brief increases reference counter by 1.
  *  \param[in] ref pointer to reference counter.
  *  \returns previous value of reference counter.
  */
+#if _MSC_VER
+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 */                  \
@@ -90,12 +109,22 @@ typedef atomic_uint_fast32_t isc_refcount_t;
                INSIST(__v > 0 && __v < UINT32_MAX);                    \
                __v;                                                    \
        })
+#endif /* _MSC_VER */
 
 /** \def isc_refcount_decrement(ref)
  *  \brief decreases reference counter by 1.
  *  \param[in] ref pointer to reference counter.
  *  \returns previous value of reference counter.
  */
+#if _MSC_VER
+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 */                  \
@@ -104,5 +133,6 @@ typedef atomic_uint_fast32_t isc_refcount_t;
                INSIST(__v > 0);                                        \
                __v;                                                    \
        })
+#endif /* _MSC_VER */
 
 ISC_LANG_ENDDECLS