Skip to content

Commit

Permalink
mxshadowsrv: Use __atomic_fetch_sub instead of __sync_fetch_and_sub
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
donald committed May 20, 2021
1 parent a171864 commit c596222
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mxshadowsrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c596222

Please sign in to comment.