Commit 35342db
Fix Windows atomic ops to return pre-operation value (match Linux/C11 semantics) (#812)
* Initial plan
* fix: use InterlockedExchangeAdd for Windows atomic ops to return old value
Replace InterlockedAdd/InterlockedIncrement/InterlockedDecrement with
InterlockedExchangeAdd which returns the value before the operation,
matching the behavior of __sync_fetch_and_add (GCC) and
atomic_fetch_add (C11).
Also fix ATOMIC_SUB macro parenthesization: -(n) instead of -n.
Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>
* fix: prefer GCC builtins over Interlocked for MinGW compatibility
Reorder #ifdef checks so GCC-based compilers (including MinGW) use
__sync_fetch_and_add builtins via a direct __GNUC__ version check,
instead of relying on __GNUC_PREREQ which is broken on MinGW.
Only pure MSVC now uses InterlockedExchangeAdd for atomic operations.
This completely avoids any MinGW compatibility concerns with Windows
Interlocked functions.
Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>1 parent 85d1265 commit 35342db
1 file changed
+13
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
| 51 | + | |
53 | 52 | | |
54 | 53 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
59 | 58 | | |
60 | | - | |
| 59 | + | |
61 | 60 | | |
62 | 61 | | |
63 | 62 | | |
64 | | - | |
| 63 | + | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| |||
0 commit comments