ATOMIC_VAR_INIT has a trivial definition
`#define ATOMIC_VAR_INIT(value) (value)`,
is deprecated in C17/C++20, and will be removed in newer standards in
newer GCC/Clang (e.g. https://reviews.llvm.org/D144196).

Signed-off-by: Fangrui Song <mask...@google.com>
---
Changes from v1:

* remove ATOMIC_VAR_INIT from lib/ovs-atomic*.h files
* update lib/ovs-atomic.h

---
 lib/dpdk.c                    |  2 +-
 lib/mpsc-queue.h              |  6 +++---
 lib/ovs-atomic-clang.h        |  2 --
 lib/ovs-atomic-gcc4+.h        |  1 -
 lib/ovs-atomic-gcc4.7+.h      |  1 -
 lib/ovs-atomic-i586.h         |  1 -
 lib/ovs-atomic-msvc.h         |  1 -
 lib/ovs-atomic-pthreads.h     |  1 -
 lib/ovs-atomic-x86_64.h       |  1 -
 lib/ovs-atomic.h              |  5 ++---
 lib/ovs-rcu.h                 |  4 ++--
 lib/ovs-replay.c              |  2 +-
 lib/versions.h                |  2 +-
 lib/vlog.c                    |  2 +-
 ofproto/ofproto-dpif-upcall.c |  4 ++--
 tests/test-atomic.c           | 12 ++++++------
 16 files changed, 19 insertions(+), 28 deletions(-)

diff --git a/lib/dpdk.c b/lib/dpdk.c
index 240babc03..d76d53f8f 100644
--- a/lib/dpdk.c
+++ b/lib/dpdk.c
@@ -47,7 +47,7 @@ VLOG_DEFINE_THIS_MODULE(dpdk);
 static FILE *log_stream = NULL;       /* Stream for DPDK log redirection */
 
 /* Indicates successful initialization of DPDK. */
-static atomic_bool dpdk_initialized = ATOMIC_VAR_INIT(false);
+static atomic_bool dpdk_initialized = false;
 
 static bool
 args_contains(const struct svec *args, const char *value)
diff --git a/lib/mpsc-queue.h b/lib/mpsc-queue.h
index 8c7109621..70c2d7a01 100644
--- a/lib/mpsc-queue.h
+++ b/lib/mpsc-queue.h
@@ -116,9 +116,9 @@ struct mpsc_queue {
 };
 
 #define MPSC_QUEUE_INITIALIZER(Q) { \
-    .head = ATOMIC_VAR_INIT(&(Q)->stub), \
-    .tail = ATOMIC_VAR_INIT(&(Q)->stub), \
-    .stub = { .next = ATOMIC_VAR_INIT(NULL) }, \
+    .head = &(Q)->stub, \
+    .tail = &(Q)->stub, \
+    .stub = { .next = NULL }, \
     .read_lock = OVS_MUTEX_INITIALIZER, \
 }
 
diff --git a/lib/ovs-atomic-clang.h b/lib/ovs-atomic-clang.h
index cdf02a512..0fc643c8a 100644
--- a/lib/ovs-atomic-clang.h
+++ b/lib/ovs-atomic-clang.h
@@ -23,8 +23,6 @@
 
 #define ATOMIC(TYPE) _Atomic(TYPE)
 
-#define ATOMIC_VAR_INIT(VALUE) (VALUE)
-
 #define atomic_init(OBJECT, VALUE) __c11_atomic_init(OBJECT, VALUE)
 
 /* Clang hard-codes these exact values internally but does not appear to
diff --git a/lib/ovs-atomic-gcc4+.h b/lib/ovs-atomic-gcc4+.h
index f9accde1a..1917df690 100644
--- a/lib/ovs-atomic-gcc4+.h
+++ b/lib/ovs-atomic-gcc4+.h
@@ -43,7 +43,6 @@ typedef enum {
 
 #define IS_LOCKLESS_ATOMIC(OBJECT) (sizeof(OBJECT) <= sizeof(void *))
 
-#define ATOMIC_VAR_INIT(VALUE) VALUE
 #define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0)
 
 static inline void
diff --git a/lib/ovs-atomic-gcc4.7+.h b/lib/ovs-atomic-gcc4.7+.h
index 846e05775..9680e546f 100644
--- a/lib/ovs-atomic-gcc4.7+.h
+++ b/lib/ovs-atomic-gcc4.7+.h
@@ -30,7 +30,6 @@ typedef enum {
     memory_order_seq_cst = __ATOMIC_SEQ_CST
 } memory_order;
 
-#define ATOMIC_VAR_INIT(VALUE) (VALUE)
 #define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0)
 
 #define atomic_thread_fence __atomic_thread_fence
diff --git a/lib/ovs-atomic-i586.h b/lib/ovs-atomic-i586.h
index 35a0959ff..2b6518652 100644
--- a/lib/ovs-atomic-i586.h
+++ b/lib/ovs-atomic-i586.h
@@ -119,7 +119,6 @@ typedef enum {
 #define IS_LOCKLESS_ATOMIC(OBJECT)                      \
     (sizeof(OBJECT) <= 8 && IS_POW2(sizeof(OBJECT)))
 
-#define ATOMIC_VAR_INIT(VALUE) VALUE
 #define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0)
 
 /*
diff --git a/lib/ovs-atomic-msvc.h b/lib/ovs-atomic-msvc.h
index fb8cd03bd..3a71f61ae 100644
--- a/lib/ovs-atomic-msvc.h
+++ b/lib/ovs-atomic-msvc.h
@@ -59,7 +59,6 @@ typedef enum {
 #define IS_LOCKLESS_ATOMIC(OBJECT)                      \
     (sizeof(OBJECT) <= 8 && IS_POW2(sizeof(OBJECT)))
 
-#define ATOMIC_VAR_INIT(VALUE) (VALUE)
 #define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0)
 
 static inline void
diff --git a/lib/ovs-atomic-pthreads.h b/lib/ovs-atomic-pthreads.h
index 570a67fe4..0e4263fe2 100644
--- a/lib/ovs-atomic-pthreads.h
+++ b/lib/ovs-atomic-pthreads.h
@@ -42,7 +42,6 @@ typedef enum {
     memory_order_seq_cst
 } memory_order;
 
-#define ATOMIC_VAR_INIT(VALUE) (VALUE)
 #define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0)
 
 static inline void
diff --git a/lib/ovs-atomic-x86_64.h b/lib/ovs-atomic-x86_64.h
index 3bdaf2f08..2f538699f 100644
--- a/lib/ovs-atomic-x86_64.h
+++ b/lib/ovs-atomic-x86_64.h
@@ -120,7 +120,6 @@ typedef enum {
 #define IS_LOCKLESS_ATOMIC(OBJECT)                      \
     (sizeof(OBJECT) <= 8 && IS_POW2(sizeof(OBJECT)))
 
-#define ATOMIC_VAR_INIT(VALUE) VALUE
 #define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0)
 
 /*
diff --git a/lib/ovs-atomic.h b/lib/ovs-atomic.h
index 8fdce0cf8..ab9ce6b2e 100644
--- a/lib/ovs-atomic.h
+++ b/lib/ovs-atomic.h
@@ -91,10 +91,9 @@
  * Life Cycle
  * ==========
  *
- * To initialize an atomic variable at its point of definition, use
- * ATOMIC_VAR_INIT:
+ * To initialize an atomic variable at its point of definition, use:
  *
- *     static atomic_int ai = ATOMIC_VAR_INIT(123);
+ *     static atomic_int ai = 123;
  *
  * To initialize an atomic variable in code, use atomic_init():
  *
diff --git a/lib/ovs-rcu.h b/lib/ovs-rcu.h
index 8b397b7fb..a1c15c126 100644
--- a/lib/ovs-rcu.h
+++ b/lib/ovs-rcu.h
@@ -175,7 +175,7 @@
 
 #if __GNUC__
 #define OVSRCU_TYPE(TYPE) struct { ATOMIC(TYPE) p; }
-#define OVSRCU_INITIALIZER(VALUE) { ATOMIC_VAR_INIT(VALUE) }
+#define OVSRCU_INITIALIZER(VALUE) { VALUE }
 #define ovsrcu_get__(TYPE, VAR, ORDER)                                  \
     ({                                                                  \
         TYPE value__;                                                   \
@@ -207,7 +207,7 @@
 #else  /* not GNU C */
 struct ovsrcu_pointer { ATOMIC(void *) p; };
 #define OVSRCU_TYPE(TYPE) struct ovsrcu_pointer
-#define OVSRCU_INITIALIZER(VALUE) { ATOMIC_VAR_INIT(VALUE) }
+#define OVSRCU_INITIALIZER(VALUE) { VALUE }
 static inline void *
 ovsrcu_get__(const struct ovsrcu_pointer *pointer, memory_order order)
 {
diff --git a/lib/ovs-replay.c b/lib/ovs-replay.c
index f386246c7..551c7f56d 100644
--- a/lib/ovs-replay.c
+++ b/lib/ovs-replay.c
@@ -34,7 +34,7 @@ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(10, 
25);
 
 static struct ovs_mutex replay_mutex = OVS_MUTEX_INITIALIZER;
 static int replay_seqno OVS_GUARDED_BY(replay_mutex) = 0;
-static atomic_int replay_state = ATOMIC_VAR_INIT(OVS_REPLAY_NONE);
+static atomic_int replay_state = OVS_REPLAY_NONE;
 
 static char *dirname = NULL;
 
diff --git a/lib/versions.h b/lib/versions.h
index d92f0a319..724880cb7 100644
--- a/lib/versions.h
+++ b/lib/versions.h
@@ -36,7 +36,7 @@ struct versions {
 };
 
 #define VERSIONS_INITIALIZER(ADD, REMOVE) \
-    (struct versions){ ADD, ATOMIC_VAR_INIT(REMOVE) }
+    (struct versions){ ADD, REMOVE }
 
 static inline void
 versions_set_remove_version(struct versions *versions, ovs_version_t version)
diff --git a/lib/vlog.c b/lib/vlog.c
index 0a615bb66..9ddea48b8 100644
--- a/lib/vlog.c
+++ b/lib/vlog.c
@@ -118,7 +118,7 @@ static struct ovs_list vlog_modules 
OVS_GUARDED_BY(log_file_mutex)
 static int syslog_fd OVS_GUARDED_BY(pattern_rwlock) = -1;
 
 /* Log facility configuration. */
-static atomic_int log_facility = ATOMIC_VAR_INIT(0);
+static atomic_int log_facility = 0;
 
 /* Facility name and its value. */
 struct vlog_facility {
diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c
index fc94078cb..914cf3f98 100644
--- a/ofproto/ofproto-dpif-upcall.c
+++ b/ofproto/ofproto-dpif-upcall.c
@@ -416,8 +416,8 @@ static int udpif_flow_unprogram(struct udpif *udpif, struct 
udpif_key *ukey,
 static upcall_callback upcall_cb;
 static dp_purge_callback dp_purge_cb;
 
-static atomic_bool enable_megaflows = ATOMIC_VAR_INIT(true);
-static atomic_bool enable_ufid = ATOMIC_VAR_INIT(true);
+static atomic_bool enable_megaflows = true;
+static atomic_bool enable_ufid = true;
 
 void
 udpif_init(void)
diff --git a/tests/test-atomic.c b/tests/test-atomic.c
index 4b1374b70..7853c3e59 100644
--- a/tests/test-atomic.c
+++ b/tests/test-atomic.c
@@ -28,7 +28,7 @@ VLOG_DEFINE_THIS_MODULE(test_atomic);
 
 #define TEST_ATOMIC_TYPE(ATOMIC_TYPE, BASE_TYPE)        \
     {                                                   \
-        ATOMIC_TYPE x = ATOMIC_VAR_INIT(1);             \
+        ATOMIC_TYPE x = 1;                              \
         BASE_TYPE value, orig;                          \
                                                         \
         atomic_read(&x, &value);                        \
@@ -71,7 +71,7 @@ VLOG_DEFINE_THIS_MODULE(test_atomic);
 #define TEST_ATOMIC_TYPE_EXPLICIT(ATOMIC_TYPE, BASE_TYPE,               \
                                   ORDER_READ, ORDER_STORE, ORDER_RMW)   \
     {                                                                   \
-        ATOMIC_TYPE x = ATOMIC_VAR_INIT(1);                             \
+        ATOMIC_TYPE x = 1;                                              \
         BASE_TYPE value, orig;                                          \
                                                                         \
         atomic_read_explicit(&x, &value, ORDER_READ);                   \
@@ -181,7 +181,7 @@ struct atomic_aux {
     ATOMIC(uint64_t) data64;
 };
 
-static ATOMIC(struct atomic_aux *) paux = ATOMIC_VAR_INIT(NULL);
+static ATOMIC(struct atomic_aux *) paux = NULL;
 static struct atomic_aux *auxes = NULL;
 
 #define ATOMIC_ITEM_COUNT 1000000
@@ -229,7 +229,7 @@ atomic_producer(void * arg1 OVS_UNUSED)
     for (i = 0; i < ATOMIC_ITEM_COUNT; i++) {
         struct atomic_aux *aux = &auxes[i];
 
-        aux->count = ATOMIC_VAR_INIT(i);
+        aux->count = i;
         aux->b = i + 42;
 
         /* Publish the new item. */
@@ -337,9 +337,9 @@ test_acq_rel(void)
     a = 0;
     aux->b = 0;
 
-    aux->count = ATOMIC_VAR_INIT(0);
+    aux->count = 0;
     atomic_init(&aux->data, NULL);
-    aux->data64 = ATOMIC_VAR_INIT(0);
+    aux->data64 = 0;
 
     reader = ovs_thread_create("reader", atomic_reader, aux);
     writer = ovs_thread_create("writer", atomic_writer, aux);
-- 
2.39.2.722.g9855ee24e9-goog

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to