[PATCH 02/17] telemetry: use previous value atomic fetch operations

Tyler Retzlaff roretzla at linux.microsoft.com
Thu Mar 2 01:47:33 CET 2023


Use __atomic_fetch_{add,and,or,sub,xor} instead of
__atomic_{add,and,or,sub,xor}_fetch when we have no interest in the
result of the operation.

Reduces unnecessary codegen that provided the result of the atomic
operation that was not used.

Change brings closer alignment with atomics available in C11 standard
and will reduce review effort when they are integrated.

Signed-off-by: Tyler Retzlaff <roretzla at linux.microsoft.com>
---
 lib/telemetry/telemetry.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c
index 7bceadc..deba7f3 100644
--- a/lib/telemetry/telemetry.c
+++ b/lib/telemetry/telemetry.c
@@ -391,7 +391,7 @@ struct socket {
 		bytes = read(s, buffer, sizeof(buffer) - 1);
 	}
 	close(s);
-	__atomic_sub_fetch(&v2_clients, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_sub(&v2_clients, 1, __ATOMIC_RELAXED);
 	return NULL;
 }
 
@@ -414,7 +414,7 @@ struct socket {
 				close(s_accepted);
 				continue;
 			}
-			__atomic_add_fetch(s->num_clients, 1,
+			__atomic_fetch_add(s->num_clients, 1,
 					__ATOMIC_RELAXED);
 		}
 		rc = pthread_create(&th, NULL, s->fn,
@@ -424,7 +424,7 @@ struct socket {
 				 strerror(rc));
 			close(s_accepted);
 			if (s->num_clients != NULL)
-				__atomic_sub_fetch(s->num_clients, 1,
+				__atomic_fetch_sub(s->num_clients, 1,
 						   __ATOMIC_RELAXED);
 			continue;
 		}
-- 
1.8.3.1



More information about the dev mailing list