Skip to content

Commit

Permalink
Fix mingw atomics (nanomsg#1601)
Browse files Browse the repository at this point in the history
* Fixes compiling on Windows with Mingw

Fixes the build error: "InterlockedDecrementAcquire64 not defined" on Mingw

* fixes semantics of InterlockedDecrementRelease64 on Mingw

From Microsoft docs, InterlockedDecrementRelease64 returns the resulting decremented value.
The equivalent function on Mingw is `__atomic_sub_fetch`, not `__atomic_fetch_sub` (which returns the previous value).
  • Loading branch information
L0PiTaL authored Jun 20, 2022
1 parent 41ce9fb commit 27701c0
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/platform/windows/win_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ static pfnSetThreadDescription set_thread_desc;
__atomic_add_fetch(a, b, __ATOMIC_RELAXED)
#define InterlockedIncrementAcquire64(a) \
__atomic_add_fetch(a, 1, __ATOMIC_ACQUIRE)
#define InterlockedDecrementAcquire64(a) \
__atomic_sub_fetch(a, 1, __ATOMIC_ACQUIRE)
#define InterlockedDecrementRelease64(a) \
__atomic_fetch_sub(a, 1, __ATOMIC_RELEASE)
__atomic_sub_fetch(a, 1, __ATOMIC_RELEASE)
#endif

#include <stdlib.h>
Expand Down

0 comments on commit 27701c0

Please sign in to comment.