2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-22 09:58:01 +00:00

treewide: Remove uses of ATOMIC_VAR_INIT.

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 <maskray@google.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
Fangrui Song 2023-02-28 18:30:56 -08:00 committed by Ilya Maximets
parent e3c821f8ca
commit 71ca8393b7
16 changed files with 19 additions and 28 deletions

View File

@ -47,7 +47,7 @@ VLOG_DEFINE_THIS_MODULE(dpdk);
static FILE *log_stream = NULL; /* Stream for DPDK log redirection */ static FILE *log_stream = NULL; /* Stream for DPDK log redirection */
/* Indicates successful initialization of DPDK. */ /* Indicates successful initialization of DPDK. */
static atomic_bool dpdk_initialized = ATOMIC_VAR_INIT(false); static atomic_bool dpdk_initialized = false;
static bool static bool
args_contains(const struct svec *args, const char *value) args_contains(const struct svec *args, const char *value)

View File

@ -116,9 +116,9 @@ struct mpsc_queue {
}; };
#define MPSC_QUEUE_INITIALIZER(Q) { \ #define MPSC_QUEUE_INITIALIZER(Q) { \
.head = ATOMIC_VAR_INIT(&(Q)->stub), \ .head = &(Q)->stub, \
.tail = ATOMIC_VAR_INIT(&(Q)->stub), \ .tail = &(Q)->stub, \
.stub = { .next = ATOMIC_VAR_INIT(NULL) }, \ .stub = { .next = NULL }, \
.read_lock = OVS_MUTEX_INITIALIZER, \ .read_lock = OVS_MUTEX_INITIALIZER, \
} }

View File

@ -23,8 +23,6 @@
#define ATOMIC(TYPE) _Atomic(TYPE) #define ATOMIC(TYPE) _Atomic(TYPE)
#define ATOMIC_VAR_INIT(VALUE) (VALUE)
#define atomic_init(OBJECT, VALUE) __c11_atomic_init(OBJECT, VALUE) #define atomic_init(OBJECT, VALUE) __c11_atomic_init(OBJECT, VALUE)
/* Clang hard-codes these exact values internally but does not appear to /* Clang hard-codes these exact values internally but does not appear to

View File

@ -43,7 +43,6 @@ typedef enum {
#define IS_LOCKLESS_ATOMIC(OBJECT) (sizeof(OBJECT) <= sizeof(void *)) #define IS_LOCKLESS_ATOMIC(OBJECT) (sizeof(OBJECT) <= sizeof(void *))
#define ATOMIC_VAR_INIT(VALUE) VALUE
#define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0) #define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0)
static inline void static inline void

View File

@ -30,7 +30,6 @@ typedef enum {
memory_order_seq_cst = __ATOMIC_SEQ_CST memory_order_seq_cst = __ATOMIC_SEQ_CST
} memory_order; } memory_order;
#define ATOMIC_VAR_INIT(VALUE) (VALUE)
#define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0) #define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0)
#define atomic_thread_fence __atomic_thread_fence #define atomic_thread_fence __atomic_thread_fence

View File

@ -119,7 +119,6 @@ typedef enum {
#define IS_LOCKLESS_ATOMIC(OBJECT) \ #define IS_LOCKLESS_ATOMIC(OBJECT) \
(sizeof(OBJECT) <= 8 && IS_POW2(sizeof(OBJECT))) (sizeof(OBJECT) <= 8 && IS_POW2(sizeof(OBJECT)))
#define ATOMIC_VAR_INIT(VALUE) VALUE
#define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0) #define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0)
/* /*

View File

@ -59,7 +59,6 @@ typedef enum {
#define IS_LOCKLESS_ATOMIC(OBJECT) \ #define IS_LOCKLESS_ATOMIC(OBJECT) \
(sizeof(OBJECT) <= 8 && IS_POW2(sizeof(OBJECT))) (sizeof(OBJECT) <= 8 && IS_POW2(sizeof(OBJECT)))
#define ATOMIC_VAR_INIT(VALUE) (VALUE)
#define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0) #define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0)
static inline void static inline void

View File

@ -42,7 +42,6 @@ typedef enum {
memory_order_seq_cst memory_order_seq_cst
} memory_order; } memory_order;
#define ATOMIC_VAR_INIT(VALUE) (VALUE)
#define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0) #define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0)
static inline void static inline void

View File

@ -120,7 +120,6 @@ typedef enum {
#define IS_LOCKLESS_ATOMIC(OBJECT) \ #define IS_LOCKLESS_ATOMIC(OBJECT) \
(sizeof(OBJECT) <= 8 && IS_POW2(sizeof(OBJECT))) (sizeof(OBJECT) <= 8 && IS_POW2(sizeof(OBJECT)))
#define ATOMIC_VAR_INIT(VALUE) VALUE
#define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0) #define atomic_init(OBJECT, VALUE) (*(OBJECT) = (VALUE), (void) 0)
/* /*

View File

@ -91,10 +91,9 @@
* Life Cycle * Life Cycle
* ========== * ==========
* *
* To initialize an atomic variable at its point of definition, use * To initialize an atomic variable at its point of definition, use:
* ATOMIC_VAR_INIT:
* *
* static atomic_int ai = ATOMIC_VAR_INIT(123); * static atomic_int ai = 123;
* *
* To initialize an atomic variable in code, use atomic_init(): * To initialize an atomic variable in code, use atomic_init():
* *

View File

@ -175,7 +175,7 @@
#if __GNUC__ #if __GNUC__
#define OVSRCU_TYPE(TYPE) struct { ATOMIC(TYPE) p; } #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) \ #define ovsrcu_get__(TYPE, VAR, ORDER) \
({ \ ({ \
TYPE value__; \ TYPE value__; \
@ -207,7 +207,7 @@
#else /* not GNU C */ #else /* not GNU C */
struct ovsrcu_pointer { ATOMIC(void *) p; }; struct ovsrcu_pointer { ATOMIC(void *) p; };
#define OVSRCU_TYPE(TYPE) struct ovsrcu_pointer #define OVSRCU_TYPE(TYPE) struct ovsrcu_pointer
#define OVSRCU_INITIALIZER(VALUE) { ATOMIC_VAR_INIT(VALUE) } #define OVSRCU_INITIALIZER(VALUE) { VALUE }
static inline void * static inline void *
ovsrcu_get__(const struct ovsrcu_pointer *pointer, memory_order order) ovsrcu_get__(const struct ovsrcu_pointer *pointer, memory_order order)
{ {

View File

@ -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 struct ovs_mutex replay_mutex = OVS_MUTEX_INITIALIZER;
static int replay_seqno OVS_GUARDED_BY(replay_mutex) = 0; 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; static char *dirname = NULL;

View File

@ -36,7 +36,7 @@ struct versions {
}; };
#define VERSIONS_INITIALIZER(ADD, REMOVE) \ #define VERSIONS_INITIALIZER(ADD, REMOVE) \
(struct versions){ ADD, ATOMIC_VAR_INIT(REMOVE) } (struct versions){ ADD, REMOVE }
static inline void static inline void
versions_set_remove_version(struct versions *versions, ovs_version_t version) versions_set_remove_version(struct versions *versions, ovs_version_t version)

View File

@ -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; static int syslog_fd OVS_GUARDED_BY(pattern_rwlock) = -1;
/* Log facility configuration. */ /* Log facility configuration. */
static atomic_int log_facility = ATOMIC_VAR_INIT(0); static atomic_int log_facility = 0;
/* Facility name and its value. */ /* Facility name and its value. */
struct vlog_facility { struct vlog_facility {

View File

@ -420,8 +420,8 @@ static int udpif_flow_unprogram(struct udpif *udpif, struct udpif_key *ukey,
static upcall_callback upcall_cb; static upcall_callback upcall_cb;
static dp_purge_callback dp_purge_cb; static dp_purge_callback dp_purge_cb;
static atomic_bool enable_megaflows = ATOMIC_VAR_INIT(true); static atomic_bool enable_megaflows = true;
static atomic_bool enable_ufid = ATOMIC_VAR_INIT(true); static atomic_bool enable_ufid = true;
void void
udpif_init(void) udpif_init(void)

View File

@ -28,7 +28,7 @@ VLOG_DEFINE_THIS_MODULE(test_atomic);
#define TEST_ATOMIC_TYPE(ATOMIC_TYPE, BASE_TYPE) \ #define TEST_ATOMIC_TYPE(ATOMIC_TYPE, BASE_TYPE) \
{ \ { \
ATOMIC_TYPE x = ATOMIC_VAR_INIT(1); \ ATOMIC_TYPE x = 1; \
BASE_TYPE value, orig; \ BASE_TYPE value, orig; \
\ \
atomic_read(&x, &value); \ atomic_read(&x, &value); \
@ -71,7 +71,7 @@ VLOG_DEFINE_THIS_MODULE(test_atomic);
#define TEST_ATOMIC_TYPE_EXPLICIT(ATOMIC_TYPE, BASE_TYPE, \ #define TEST_ATOMIC_TYPE_EXPLICIT(ATOMIC_TYPE, BASE_TYPE, \
ORDER_READ, ORDER_STORE, ORDER_RMW) \ ORDER_READ, ORDER_STORE, ORDER_RMW) \
{ \ { \
ATOMIC_TYPE x = ATOMIC_VAR_INIT(1); \ ATOMIC_TYPE x = 1; \
BASE_TYPE value, orig; \ BASE_TYPE value, orig; \
\ \
atomic_read_explicit(&x, &value, ORDER_READ); \ atomic_read_explicit(&x, &value, ORDER_READ); \
@ -181,7 +181,7 @@ struct atomic_aux {
ATOMIC(uint64_t) data64; 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; static struct atomic_aux *auxes = NULL;
#define ATOMIC_ITEM_COUNT 1000000 #define ATOMIC_ITEM_COUNT 1000000
@ -229,7 +229,7 @@ atomic_producer(void * arg1 OVS_UNUSED)
for (i = 0; i < ATOMIC_ITEM_COUNT; i++) { for (i = 0; i < ATOMIC_ITEM_COUNT; i++) {
struct atomic_aux *aux = &auxes[i]; struct atomic_aux *aux = &auxes[i];
aux->count = ATOMIC_VAR_INIT(i); aux->count = i;
aux->b = i + 42; aux->b = i + 42;
/* Publish the new item. */ /* Publish the new item. */
@ -337,9 +337,9 @@ test_acq_rel(void)
a = 0; a = 0;
aux->b = 0; aux->b = 0;
aux->count = ATOMIC_VAR_INIT(0); aux->count = 0;
atomic_init(&aux->data, NULL); atomic_init(&aux->data, NULL);
aux->data64 = ATOMIC_VAR_INIT(0); aux->data64 = 0;
reader = ovs_thread_create("reader", atomic_reader, aux); reader = ovs_thread_create("reader", atomic_reader, aux);
writer = ovs_thread_create("writer", atomic_writer, aux); writer = ovs_thread_create("writer", atomic_writer, aux);