diff mbox series

[v1,7/8] examples/server_node_efd: use compiler atomics for sync

Message ID 20210819070908.25773-8-joyce.kong@arm.com (mailing list archive)
State Superseded
Delegated to: Thomas Monjalon
Headers show
Series use compiler atomic builtins for examples | expand

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Joyce Kong Aug. 19, 2021, 7:09 a.m. UTC
Convert rte_atomic32_test_and_set to compiler CAS atomic
operation for display_stats sync.

Signed-off-by: Joyce Kong <joyce.kong@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
---
 examples/server_node_efd/server/main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/examples/server_node_efd/server/main.c b/examples/server_node_efd/server/main.c
index 7d07131dbf..b69beb012c 100644
--- a/examples/server_node_efd/server/main.c
+++ b/examples/server_node_efd/server/main.c
@@ -22,7 +22,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>
@@ -180,10 +179,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;
 
 	/* Only one core should display stats */
-	if (rte_atomic32_test_and_set(&display_stats)) {
+	uint32_t display_init = 0;
+	if (__atomic_compare_exchange_n(&display_stats, &display_init, 1, 0,
+			__ATOMIC_RELAXED, __ATOMIC_RELAXED)) {
 		const unsigned int sleeptime = 1;
 
 		printf("Core %u displaying statistics\n", rte_lcore_id());