On 2/24/23 22:34, Fangrui Song via dev wrote:
> 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 <[email protected]>
Hi. Thanks for the patch.
It is interesting, and I guess, we can just remove the
initialization macro. But if we're going to do that, we
should also remove definitions for different compilers
in lib/ovs-atomic-*.h and update the documentation in
lib/ovs-atomic.h.
Ideally, add a check to utilities/checkpatch.py to warn
about use of a deprecated macro.
Best regards, Ilya Maximets.
> ---
> lib/dpdk.c | 2 +-
> lib/mpsc-queue.h | 6 +++---
> 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 ++++++------
> 8 files changed, 17 insertions(+), 17 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-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);
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev