# are acceptable as C++.
noinst_LTLIBRARIES += include/openvswitch/libcxxtest.la
nodist_include_openvswitch_libcxxtest_la_SOURCES = include/openvswitch/cxxtest.cc
-include/openvswitch/cxxtest.cc: include/openvswitch/automake.mk
- $(AM_V_GEN)for header in $(openvswitchinclude_HEADERS); do \
- echo $$header; \
- done | sed 's,^include/\(.*\)$$,#include <\1>,' > $@
+include/openvswitch/cxxtest.cc: \
+ include/openvswitch/automake.mk $(top_builddir)/config.status
+ $(AM_V_GEN){ echo "#include <config.h>"; \
+ for header in $(openvswitchinclude_HEADERS); do \
+ echo $$header; \
+ done | sed 's,^include/\(.*\)$$,#include <\1>,'; } > $@
endif
# OVS does not use C++ itself, but it provides public header files
--- /dev/null
+/* This header implements atomic operation primitives on compilers that
+ * have built-in support for ++C11 <atomic> */
+#ifndef IN_OVS_ATOMIC_H
+#error "This header should only be included indirectly via ovs-atomic.h."
+#endif
+
+#include <atomic>
+
+#define ATOMIC(TYPE) std::atomic<TYPE>
+
+using std::atomic_init;
+
+using std::memory_order_relaxed;
+using std::memory_order_consume;
+using std::memory_order_acquire;
+using std::memory_order_release;
+using std::memory_order_acq_rel;
+using std::memory_order_seq_cst;
+
+using std::atomic_thread_fence;
+using std::atomic_signal_fence;
+using std::atomic_is_lock_free;
+
+using std::atomic_store;
+using std::atomic_store_explicit;
+
+using std::atomic_compare_exchange_strong;
+using std::atomic_compare_exchange_strong_explicit;
+using std::atomic_compare_exchange_weak;
+using std::atomic_compare_exchange_weak_explicit;
+
+#define atomic_read(SRC, DST) \
+ atomic_read_explicit(SRC, DST, memory_order_seq_cst)
+#define atomic_read_explicit(SRC, DST, ORDER) \
+ (*(DST) = std::atomic_load_explicit(SRC, ORDER), \
+ (void) 0)
+
+#define atomic_add(RMW, ARG, ORIG) \
+ atomic_add_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
+#define atomic_sub(RMW, ARG, ORIG) \
+ atomic_sub_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
+#define atomic_or(RMW, ARG, ORIG) \
+ atomic_or_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
+#define atomic_xor(RMW, ARG, ORIG) \
+ atomic_xor_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
+#define atomic_and(RMW, ARG, ORIG) \
+ atomic_and_explicit(RMW, ARG, ORIG, memory_order_seq_cst)
+
+#define atomic_add_explicit(RMW, ARG, ORIG, ORDER) \
+ (*(ORIG) = std::atomic_fetch_add_explicit(RMW, ARG, ORDER), (void) 0)
+#define atomic_sub_explicit(RMW, ARG, ORIG, ORDER) \
+ (*(ORIG) = std::atomic_fetch_sub_explicit(RMW, ARG, ORDER), (void) 0)
+#define atomic_or_explicit(RMW, ARG, ORIG, ORDER) \
+ (*(ORIG) = std::atomic_fetch_or_explicit(RMW, ARG, ORDER), (void) 0)
+#define atomic_xor_explicit(RMW, ARG, ORIG, ORDER) \
+ (*(ORIG) = std::atomic_fetch_xor_explicit(RMW, ARG, ORDER), (void) 0)
+#define atomic_and_explicit(RMW, ARG, ORIG, ORDER) \
+ (*(ORIG) = std::atomic_fetch_and_explicit(RMW, ARG, ORDER), (void) 0)
+
+using std::atomic_flag;
+using std::atomic_flag_test_and_set_explicit;
+using std::atomic_flag_test_and_set;
+using std::atomic_flag_clear_explicit;
+using std::atomic_flag_clear;
#include "ovs-atomic-pthreads.h"
#elif __has_extension(c_atomic)
#include "ovs-atomic-clang.h"
- #elif HAVE_STDATOMIC_H
+ #elif HAVE_ATOMIC && __cplusplus >= 201103L
+ #include "ovs-atomic-c++.h"
+ #elif HAVE_STDATOMIC_H && !defined(__cplusplus)
#include "ovs-atomic-c11.h"
- #elif __GNUC__ >= 5
+ #elif __GNUC__ >= 5 && !defined(__cplusplus)
#error "GCC 5+ should have <stdatomic.h>"
- #elif __GNUC__ >= 4 && __GNUC_MINOR__ >= 7
+ #elif __GNUC__ >= 5 || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 7)
#include "ovs-atomic-gcc4.7+.h"
#elif __GNUC__ && defined(__x86_64__)
#include "ovs-atomic-x86_64.h"
{
unsigned int old;
- atomic_add_relaxed(&count->count, 1, &old);
+ atomic_add_relaxed(&count->count, 1u, &old);
return old;
}
{
unsigned int old;
- atomic_sub_relaxed(&count->count, 1, &old);
+ atomic_sub_relaxed(&count->count, 1u, &old);
return old;
}
static inline void
ovs_refcount_init(struct ovs_refcount *refcount)
{
- atomic_init(&refcount->count, 1);
+ atomic_init(&refcount->count, 1u);
}
/* Increments 'refcount'.
{
unsigned int old_refcount;
- atomic_add_explicit(&refcount->count, 1, &old_refcount,
+ atomic_add_explicit(&refcount->count, 1u, &old_refcount,
memory_order_relaxed);
ovs_assert(old_refcount > 0);
}
{
unsigned int old_refcount;
- atomic_sub_explicit(&refcount->count, 1, &old_refcount,
+ atomic_sub_explicit(&refcount->count, 1u, &old_refcount,
memory_order_release);
ovs_assert(old_refcount > 0);
if (old_refcount == 1) {
{
unsigned int old_refcount;
- atomic_sub_explicit(&refcount->count, 1, &old_refcount,
+ atomic_sub_explicit(&refcount->count, 1u, &old_refcount,
memory_order_relaxed);
ovs_assert(old_refcount > 0);
return old_refcount;