examples/multi_process: use compiler atomics for sync
authorJoyce Kong <joyce.kong@arm.com>
Wed, 13 Oct 2021 18:54:01 +0000 (13:54 -0500)
committerDavid Marchand <david.marchand@redhat.com>
Tue, 19 Oct 2021 15:15:57 +0000 (17:15 +0200)
Convert rte_atomic32_test_and_set usage to compiler atomic
CAS operation for display_stats sync.

Signed-off-by: Joyce Kong <joyce.kong@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
examples/multi_process/client_server_mp/mp_server/main.c

index 9bcee46..b4761eb 100644 (file)
@@ -20,7 +20,6 @@
 #include <rte_per_lcore.h>
 #include <rte_lcore.h>
 #include <rte_branch_prediction.h>
-#include <rte_atomic.h>
 #include <rte_ring.h>
 #include <rte_log.h>
 #include <rte_debug.h>
@@ -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());