From 9b882c5b87872b6c00c7bb2d4bba7191be8648fa Mon Sep 17 00:00:00 2001 From: Joyce Kong Date: Wed, 13 Oct 2021 13:54:01 -0500 Subject: [PATCH] examples/multi_process: use compiler atomics for sync Convert rte_atomic32_test_and_set usage to compiler atomic CAS operation for display_stats sync. Signed-off-by: Joyce Kong Reviewed-by: Ruifeng Wang --- examples/multi_process/client_server_mp/mp_server/main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/multi_process/client_server_mp/mp_server/main.c b/examples/multi_process/client_server_mp/mp_server/main.c index 9bcee460fd..b4761ebc7b 100644 --- a/examples/multi_process/client_server_mp/mp_server/main.c +++ b/examples/multi_process/client_server_mp/mp_server/main.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -158,10 +157,12 @@ static int sleep_lcore(__rte_unused void *dummy) { /* Used to pick a display thread - static, so zero-initialised */ - static rte_atomic32_t display_stats; + static uint32_t display_stats; + uint32_t status = 0; /* Only one core should display stats */ - if (rte_atomic32_test_and_set(&display_stats)) { + if (__atomic_compare_exchange_n(&display_stats, &status, 1, 0, + __ATOMIC_RELAXED, __ATOMIC_RELAXED)) { const unsigned sleeptime = 1; printf("Core %u displaying statistics\n", rte_lcore_id()); -- 2.20.1