]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
atomics: remove spinlocked fallback
authorVictor Julien <victor@inliniac.net>
Wed, 4 Mar 2020 14:45:15 +0000 (15:45 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 16 Apr 2020 12:37:34 +0000 (14:37 +0200)
configure.ac
src/util-atomic.h

index d900c1e686cb2e88515cc784b98629f9b1823c2d..67a590d1abf1a9bac0644736cae0cb2abf8aec30 100644 (file)
     case "$compiler" in
         clang)
             CLANG_CFLAGS="-Wextra -Werror-implicit-function-declaration -Wno-error=unused-command-line-argument"
-            AC_MSG_CHECKING([clang __sync_bool_compare_and_swap support])
-            AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]],
-                [[ unsigned int i = 0; (void)__sync_bool_compare_and_swap(&i, 1, 1);]])],
-                [
-                    AC_DEFINE([__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1], [1], [Fake GCC atomic support])
-                    AC_DEFINE([__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2], [1], [Fake GCC atomic support])
-                    AC_DEFINE([__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4], [1], [Fake GCC atomic support])
-                    AC_DEFINE([__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8], [1], [Fake GCC atomic support])
-                    AC_MSG_RESULT([yes])],
-                [AC_MSG_RESULT([no])])
             AC_SUBST(CLANG_CFLAGS)
             ;;
         gcc)
index c0b2125944c9d14dd55636707dbaf27106e37c69..3424d04f01cbea6f6b97afa30b7db9ff22a0cd2f 100644 (file)
  * \author Victor Julien <victor@inliniac.net>
  * \author Pablo Rincon <pablo.rincon.crespo@gmail.com>
  *
- * API for atomic operations. Uses atomic instructions (GCC only at this time)
- * where available, falls back to (spin)locked* operations otherwise.
+ * API for atomic operations. Uses atomic instructions (GCC only at this time).
  *
  * To prevent developers from accidentally working with the atomic variables
  * directly instead of through the proper macro's, a marco trick is performed
  * that exposes different variable names than the developer uses. So if the dev
  * uses "somevar", internally "somevar_sc_atomic__" is used.
- *
- * Where available, we use __sync_fetch_and_add and
- * __sync_bool_compare_and_swap. If those are unavailable, the API
- * transparently created a matching (spin)lock for each atomic variable. The
- * lock will be named "somevar_sc_lock__"
- *
- * (*) where spinlocks are unavailable, the threading api falls back to mutex
  */
 
 
 #ifndef __UTIL_ATOMIC_H__
 #define __UTIL_ATOMIC_H__
 
-/* test if we have atomic operations support */
-#if (!defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) || !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || \
-     !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2) || !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1))
-
-/* Do not have atomic operations support, so implement them with locks. */
-
-/**
- *  \brief wrapper to declare an atomic variable including a (spin) lock
- *         to protect it.
- *
- *  \warning Variable and lock are _not_ initialized.
- */
-#define SC_ATOMIC_DECLARE(type, name) \
-    type name ## _sc_atomic__; \
-    SCSpinlock name ## _sc_lock__
-
-/**
- *  \brief wrapper to reference an atomic variable already declared on another file (including the spin lock)
- *
- */
-#define SC_ATOMIC_EXTERN(type, name) \
-    extern type name ## _sc_atomic__; \
-    extern SCSpinlock name ## _sc_lock__
-
-/**
- *  \brief wrapper to declare an atomic variable including a (spin) lock
- *         to protect it and initialize them.
- */
-#define SC_ATOMIC_DECL_AND_INIT(type, name) \
-    type name ## _sc_atomic__ = 0; \
-    SCSpinlock name ## _sc_lock__; \
-    SCSpinInit(&(name ## _sc_lock__), 0)
-
-/**
- *  \brief Initialize the previously declared atomic variable and it's
- *         lock.
- */
-#define SC_ATOMIC_INIT(name) do { \
-        SCSpinInit(&(name ## _sc_lock__), 0); \
-        (name ## _sc_atomic__) = 0; \
-    } while(0)
-
-/**
- *  \brief Initialize the previously declared atomic variable and it's
- *         lock.
- */
-#define SC_ATOMIC_RESET(name) do { \
-        (name ## _sc_atomic__) = 0; \
-    } while(0)
-
-/**
- *  \brief Destroy the lock used to protect this variable
- */
-#define SC_ATOMIC_DESTROY(name) do { \
-        SCSpinDestroy(&(name ## _sc_lock__)); \
-    } while (0)
-
-/**
- *  \brief add a value to our atomic variable
- *
- *  \param name the atomic variable
- *  \param val the value to add to the variable
- */
-#define SC_ATOMIC_ADD(name, val) ({\
-    typeof(name ## _sc_atomic__) var; \
-    do { \
-        SCSpinLock(&(name ## _sc_lock__)); \
-        (name ## _sc_atomic__) += (val); \
-        var = (name ## _sc_atomic__); \
-        SCSpinUnlock(&(name ## _sc_lock__)); \
-    } while(0); \
-    var ; \
-})
-
-/**
- *  \brief sub a value from our atomic variable
- *
- *  \param name the atomic variable
- *  \param val the value to sub from the variable
- */
-#define SC_ATOMIC_SUB(name, val) ({ \
-    typeof(name ## _sc_atomic__) var; \
-    do { \
-        SCSpinLock(&(name ## _sc_lock__)); \
-        (name ## _sc_atomic__) -= (val); \
-        var = (name ## _sc_atomic__); \
-        SCSpinUnlock(&(name ## _sc_lock__)); \
-    } while(0); \
-    var ; \
-})
-
-/**
- *  \brief Bitwise AND a value from our atomic variable
- *
- *  \param name the atomic variable
- *  \param val the value to sub from the variable
- */
-#define SC_ATOMIC_AND(name, val) \
-    do { \
-        SCSpinLock(&(name ## _sc_lock__)); \
-        (name ## _sc_atomic__) &= (val); \
-        SCSpinUnlock(&(name ## _sc_lock__)); \
-    } while(0)
-
-/**
- *  \brief Bitwise OR a value from our atomic variable
- *
- *  \param name the atomic variable
- *  \param val the value to sub from the variable
- */
-#define SC_ATOMIC_OR(name, val) \
-    do { \
-        SCSpinLock(&(name ## _sc_lock__)); \
-        (name ## _sc_atomic__) |= (val); \
-        SCSpinUnlock(&(name ## _sc_lock__)); \
-    } while(0)
-
-/**
- *  \brief Bitwise NAND a value from our atomic variable
- *
- *  \param name the atomic variable
- *  \param val the value to sub from the variable
- */
-#define SC_ATOMIC_NAND(name, val) \
-    do { \
-        SCSpinLock(&(name ## _sc_lock__)); \
-        (name ## _sc_atomic__) = ~(name ## _sc_atomic__) & (val); \
-        SCSpinUnlock(&(name ## _sc_lock__)); \
-    } while(0)
-
-/**
- *  \brief Bitwise XOR a value from our atomic variable
- *
- *  \param name the atomic variable
- *  \param val the value to sub from the variable
- */
-#define SC_ATOMIC_XOR(name, val) \
-    do { \
-        SCSpinLock(&(name ## _sc_lock__)); \
-        (name ## _sc_atomic__) ^= (val); \
-        SCSpinUnlock(&(name ## _sc_lock__)); \
-    } while(0)
-
-/**
- *  \brief Get the value from the atomic variable.
- *
- *  \retval var value
- */
-#define SC_ATOMIC_GET(name) ({ \
-    typeof(name ## _sc_atomic__) var; \
-    do { \
-        SCSpinLock(&(name ## _sc_lock__)); \
-        var = (name ## _sc_atomic__); \
-        SCSpinUnlock(&(name ## _sc_lock__)); \
-    } while (0); \
-    var; \
-})
-
-/**
- *  \brief Set the value for the atomic variable.
- *
- *  \retval var value
- */
-#define SC_ATOMIC_SET(name, val) ({       \
-    typeof(name ## _sc_atomic__) var; \
-    do { \
-        SCSpinLock(&(name ## _sc_lock__)); \
-        var = (name ## _sc_atomic__) = val; \
-        SCSpinUnlock(&(name ## _sc_lock__)); \
-    } while (0); \
-    var; \
-})
-
-/**
- *  \brief atomic Compare and Switch
- *
- *  \warning "name" is passed to us as "&var"
- */
-#define SC_ATOMIC_CAS(name, cmpval, newval) ({ \
-    char r = 0; \
-    do { \
-        SCSpinLock((name ## _sc_lock__)); \
-        if (*(name ## _sc_atomic__) == (cmpval)) { \
-            *(name ## _sc_atomic__) = (newval); \
-            r = 1; \
-        } \
-        SCSpinUnlock((name ## _sc_lock__)); \
-    } while(0); \
-    r; \
-})
-
-#else /* we do have support for CAS */
-
 /**
  *  \brief wrapper for OS/compiler specific atomic compare and swap (CAS)
  *         function.
 #define SCAtomicSubAndFetch(addr, value) \
     __sync_sub_and_fetch((addr), (value))
 
-
-
 /**
  *  \brief wrapper for OS/compiler specific atomic fetch and "AND"
  *         function.
 #define SCAtomicFetchAndXor(addr, value) \
     __sync_fetch_and_xor((addr), (value))
 
-
 /**
  *  \brief wrapper for OS/compiler specific atomic fetch and or
  *         function.
         ;                                                       \
         })
 
-#endif /* !no atomic operations */
-
 void SCAtomicRegisterTests(void);
 
 #endif /* __UTIL_ATOMIC_H__ */