ovs-thread: Quiesce in xpthread_barrier_wait().
[sliver-openvswitch.git] / lib / ovs-atomic-locked.h
1 /* This header implements atomic operation locking helpers. */
2 #ifndef IN_OVS_ATOMIC_H
3 #error "This header should only be included indirectly via ovs-atomic.h."
4 #endif
5
6 #define OVS_ATOMIC_LOCKED_IMPL 1
7
8 void atomic_lock__(void *);
9 void atomic_unlock__(void *);
10
11 #define atomic_store_locked(DST, SRC)           \
12     (atomic_lock__(DST),                        \
13      *(DST) = (SRC),                            \
14      atomic_unlock__(DST),                      \
15      (void) 0)
16
17 #define atomic_read_locked(SRC, DST)            \
18     (atomic_lock__(SRC),                        \
19      *(DST) = *(SRC),                           \
20      atomic_unlock__(SRC),                      \
21      (void) 0)
22
23 #define atomic_op_locked_add +=
24 #define atomic_op_locked_sub -=
25 #define atomic_op_locked_or  |=
26 #define atomic_op_locked_xor ^=
27 #define atomic_op_locked_and &=
28 #define atomic_op_locked(RMW, OP, OPERAND, ORIG)    \
29     (atomic_lock__(RMW),                            \
30      *(ORIG) = *(RMW),                              \
31      *(RMW) atomic_op_locked_##OP (OPERAND),        \
32      atomic_unlock__(RMW))