From 749fc2613de92d4b3e70f09d8188b6b3251a3a44 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sun, 6 Jun 2010 15:17:58 +0200 Subject: [PATCH] Add subtracktion wrapper to the atomic api. --- src/util-atomic.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/util-atomic.h b/src/util-atomic.h index 1ae62235bd..1f8b44e17a 100644 --- a/src/util-atomic.h +++ b/src/util-atomic.h @@ -89,6 +89,19 @@ SCSpinUnlock(&(name ## _sc_lock__)); \ } while(0) +/** + * \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) \ + do { \ + SCSpinLock(&(name ## _sc_lock__)); \ + (name ## _sc_atomic__) -= (val); \ + SCSpinUnlock(&(name ## _sc_lock__)); \ + } while(0) + /** * \brief Get the value from the atomic variable. * @@ -148,6 +161,16 @@ #define SCAtomicFetchAndAdd(addr, value) \ __sync_fetch_and_add((addr), (value)) +/** + * \brief wrapper for OS/compiler specific atomic fetch and sub + * function. + * + * \param addr Address of the variable to add to + * \param value Value to sub from the variable at addr + */ +#define SCAtomicFetchAndSub(addr, value) \ + __sync_fetch_and_sub((addr), (value)) + /** * \brief wrapper for declaring atomic variables. * @@ -191,6 +214,15 @@ #define SC_ATOMIC_ADD(name, val) \ SCAtomicFetchAndAdd(&(name ## _sc_atomic__), (val)); +/** + * \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) \ + SCAtomicFetchAndSub(&(name ## _sc_atomic__), (val)); + /** * \brief atomic Compare and Switch *