From c596222847d17e37c213712299333338c76c9e2d Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Thu, 20 May 2021 16:14:32 +0200 Subject: [PATCH] mxshadowsrv: Use __atomic_fetch_sub instead of __sync_fetch_and_sub MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Quote gcc manual: "These functions are intended to replace the legacy ‘__sync’ builtins. The main difference is that the memory order that is requested is a parameter to the functions. New code should always use the ‘__atomic’ builtins rather than the ‘__sync’ builtins. Same assembler code generated on x86_64 for both builtins and no matter what memory order is specified: lock xaddl %eax, debug_remaining_connects(%rip) On ppc, however, __sync_fetch_and_sub creates code for sequential consistency and puts a "sync" instruction before the decrement (which is done atomicially between "lwarx" and "stwcx" instructions) and a "isync" instruction behind it. These two instructions are omitted when only relaxed consistency is requested: sync # optional L22: lwarx 9,0,27 addi 10,9,-1 stwcx. 10,0,27 bne 0,.L22 isync # optional Not, that it would matter at all :-) Make this change anyway to get used to the recommended builtins. --- mxshadowsrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxshadowsrv.c b/mxshadowsrv.c index 7e4614b..b8af131 100644 --- a/mxshadowsrv.c +++ b/mxshadowsrv.c @@ -193,7 +193,7 @@ static void *client_thread(void *arg) { while (1) { #ifdef DEBUG_MAX_CONNECTS - if ( __sync_fetch_and_sub(&debug_remaining_connects, 1) <= 0) + if ( __atomic_fetch_sub(&debug_remaining_connects, 1, __ATOMIC_RELAXED) <= 0) return NULL; #endif int _cleanup_(free_fd) socket = accept4(listen_socket, NULL, NULL, SOCK_NONBLOCK);