X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fovs-atomic-pthreads.h;h=33270c6a2a28ef58429cdd12cb2b0590ec56e102;hb=c5cf10598f8c9f4428291e9df3ecd72a05fb1ccf;hp=7b742cda0cd333c0d2cd5088fbdcffc12c996640;hpb=1bd2c9edc3455a73e92dbeac7dce8f7754d4b39f;p=sliver-openvswitch.git diff --git a/lib/ovs-atomic-pthreads.h b/lib/ovs-atomic-pthreads.h index 7b742cda0..33270c6a2 100644 --- a/lib/ovs-atomic-pthreads.h +++ b/lib/ovs-atomic-pthreads.h @@ -24,7 +24,6 @@ #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 @@ -45,7 +44,6 @@ typedef enum { #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) @@ -90,15 +88,43 @@ atomic_signal_fence(memory_order order OVS_UNUSED) typedef struct { bool b; - pthread_mutex_t mutex; } atomic_flag; -#define ATOMIC_FLAG_INIT { false, PTHREAD_MUTEX_INITIALIZER } +#define ATOMIC_FLAG_INIT { false } -void atomic_flag_init(volatile atomic_flag *); -void atomic_flag_destroy(volatile atomic_flag *); +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); + + return old_value; +} + +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); +} -bool atomic_flag_test_and_set(volatile atomic_flag *); -bool atomic_flag_test_and_set_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); +} -void atomic_flag_clear(volatile atomic_flag *); -void atomic_flag_clear_explicit(volatile atomic_flag *, memory_order); +static inline void +atomic_flag_clear_explicit(volatile atomic_flag *flag, + memory_order order OVS_UNUSED) +{ + atomic_flag_clear(flag); +}