]> git.puffer.fish Git - mirror/frr.git/commitdiff
libs: add atomic xxx_and_fetch apis 2933/head
authorMark Stapp <mjs@voltanet.io>
Tue, 28 Aug 2018 16:48:58 +0000 (12:48 -0400)
committerMark Stapp <mjs@voltanet.io>
Tue, 28 Aug 2018 16:48:58 +0000 (12:48 -0400)
We have the fetch_and_xxx apis, which return the _old_ value;
adding the xxx_and_fetch versions, which return the new value.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
lib/frratomic.h

index 689b25255d9e41428a32fc65f54475a45f7062f6..113f46c075bf78d8e093315287b4ff612b87e7d4 100644 (file)
 #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