]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/frratomic.h
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / frratomic.h
index 689b25255d9e41428a32fc65f54475a45f7062f6..1f1d1b569a59cfc60163c1c8085ff7c7c6dafe77 100644 (file)
 #ifdef HAVE_STDATOMIC_H
 #include <stdatomic.h>
 
+/* These are available in gcc, but not in stdatomic */
+#define atomic_add_fetch_explicit __atomic_add_fetch
+#define atomic_sub_fetch_explicit __atomic_sub_fetch
+#define atomic_and_fetch_explicit __atomic_and_fetch
+#define atomic_or_fetch_explicit __atomic_or_fetch
+
 /* gcc 4.7 and newer */
 #elif defined(HAVE___ATOMIC)
 
 #define atomic_fetch_and_explicit __atomic_fetch_and
 #define atomic_fetch_or_explicit __atomic_fetch_or
 
+#define atomic_add_fetch_explicit __atomic_add_fetch
+#define atomic_sub_fetch_explicit __atomic_sub_fetch
+#define atomic_and_fetch_explicit __atomic_and_fetch
+#define atomic_or_fetch_explicit __atomic_or_fetch
+
 #define atomic_compare_exchange_weak_explicit(atom, expect, desire, mem1,      \
                                              mem2)                            \
        __atomic_compare_exchange_n(atom, expect, desire, 1, mem1, mem2)
                *_expect = rval;                                               \
                ret;                                                           \
        })
+
 #define atomic_fetch_and_explicit(ptr, val, mem)                               \
        ({                                                                     \
                __sync_synchronize();                                          \
                rval;                                                          \
        })
 
+#define atomic_add_fetch_explicit(ptr, val, mem)                               \
+       ({                                                                     \
+               __sync_synchronize();                                          \
+               typeof(*ptr) rval = __sync_add_and_fetch((ptr), (val));        \
+               __sync_synchronize();                                          \
+               rval;                                                          \
+       })
+#define atomic_sub_fetch_explicit(ptr, val, mem)                               \
+       ({                                                                     \
+               __sync_synchronize();                                          \
+               typeof(*ptr) rval = __sync_sub_and_fetch((ptr), (val));        \
+               __sync_synchronize();                                          \
+               rval;                                                          \
+       })
+
+#define atomic_and_fetch_explicit(ptr, val, mem)                               \
+       ({                                                                     \
+               __sync_synchronize();                                          \
+               typeof(*ptr) rval = __sync_and_and_fetch(ptr, val);            \
+               __sync_synchronize();                                          \
+               rval;                                                          \
+       })
+#define atomic_or_fetch_explicit(ptr, val, mem)                                \
+       ({                                                                     \
+               __sync_synchronize();                                          \
+               typeof(*ptr) rval = __sync_or_and_fetch(ptr, val);             \
+               __sync_synchronize();                                          \
+               rval;                                                          \
+       })
+
 #else /* !HAVE___ATOMIC && !HAVE_STDATOMIC_H */
 #error no atomic functions...
 #endif