#define OVS_ATOMIC_PTHREADS_IMPL 1
#define ATOMIC(TYPE) TYPE
-#include "ovs-atomic-types.h"
#define ATOMIC_BOOL_LOCK_FREE 0
#define ATOMIC_CHAR_LOCK_FREE 0
#define ATOMIC_VAR_INIT(VALUE) (VALUE)
#define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0)
-#define atomic_destroy(OBJECT) ((void) (OBJECT))
static inline void
atomic_thread_fence(memory_order order OVS_UNUSED)
#define atomic_read_explicit(SRC, DST, ORDER) \
((void) (ORDER), atomic_read(SRC, DST))
+#define atomic_compare_exchange_strong(DST, EXP, SRC) \
+ atomic_compare_exchange_locked(DST, EXP, SRC)
+#define atomic_compare_exchange_strong_explicit(DST, EXP, SRC, ORD1, ORD2) \
+ ((void) (ORD1), (void) (ORD2), \
+ atomic_compare_exchange_strong(DST, EXP, SRC))
+#define atomic_compare_exchange_weak \
+ atomic_compare_exchange_strong
+#define atomic_compare_exchange_weak_explicit \
+ atomic_compare_exchange_strong_explicit
+
#define atomic_add(RMW, ARG, ORIG) atomic_op_locked(RMW, add, ARG, ORIG)
#define atomic_sub(RMW, ARG, ORIG) atomic_op_locked(RMW, sub, ARG, ORIG)
#define atomic_or( RMW, ARG, ORIG) atomic_op_locked(RMW, or, ARG, ORIG)
typedef struct {
bool b;
- pthread_mutex_t mutex;
} atomic_flag;
-#define ATOMIC_FLAG_INIT { false, PTHREAD_MUTEX_INITIALIZER }
+#define ATOMIC_FLAG_INIT { false }
+
+static inline bool
+atomic_flag_test_and_set(volatile atomic_flag *flag_)
+{
+ atomic_flag *flag = CONST_CAST(atomic_flag *, flag_);
+ bool old_value;
+
+ atomic_lock__(flag);
+ old_value = flag->b;
+ flag->b = true;
+ atomic_unlock__(flag);
-void atomic_flag_init(volatile atomic_flag *);
-void atomic_flag_destroy(volatile atomic_flag *);
+ return old_value;
+}
-bool atomic_flag_test_and_set(volatile atomic_flag *);
-bool atomic_flag_test_and_set_explicit(volatile atomic_flag *, memory_order);
+static inline bool
+atomic_flag_test_and_set_explicit(volatile atomic_flag *flag,
+ memory_order order OVS_UNUSED)
+{
+ return atomic_flag_test_and_set(flag);
+}
-void atomic_flag_clear(volatile atomic_flag *);
-void atomic_flag_clear_explicit(volatile atomic_flag *, memory_order);
+static inline void
+atomic_flag_clear(volatile atomic_flag *flag_)
+{
+ atomic_flag *flag = CONST_CAST(atomic_flag *, flag_);
+
+ atomic_lock__(flag);
+ flag->b = false;
+ atomic_unlock__(flag);
+}
+
+static inline void
+atomic_flag_clear_explicit(volatile atomic_flag *flag,
+ memory_order order OVS_UNUSED)
+{
+ atomic_flag_clear(flag);
+}