Skip to content

Commit 078dc05

Browse files
committed
we need 64bit swap
1 parent 9bcc3b4 commit 078dc05

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

thpool.c

+10-11
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,22 @@ this is not part of original thpool, thats me hacking it to work on windows
2727
#endif
2828
#include <stdbool.h>
2929

30-
typedef volatile LONG atomic_int;
31-
typedef atomic_int atomic_bool;
30+
typedef volatile intptr_t atomic_int;
3231

33-
static void atomic_store(atomic_int* ptr, LONG val) {
34-
InterlockedExchange(ptr, val);
32+
static void atomic_store(atomic_int* ptr, intptr_t val) {
33+
InterlockedExchange64(ptr, val);
3534
}
36-
static LONG atomic_load(atomic_int* ptr) {
37-
return InterlockedCompareExchange(ptr, 0, 0);
35+
static intptr_t atomic_load(atomic_int* ptr) {
36+
return InterlockedCompareExchange64(ptr, 0, 0);
3837
}
39-
static LONG atomic_fetch_add(atomic_int* ptr, LONG inc) {
40-
return InterlockedExchangeAdd(ptr, inc);
38+
static intptr_t atomic_fetch_add(atomic_int* ptr, intptr_t inc) {
39+
return InterlockedExchangeAdd64(ptr, inc);
4140
}
42-
static LONG atomic_fetch_sub(atomic_int* ptr, LONG dec) {
41+
static intptr_t atomic_fetch_sub(atomic_int* ptr, intptr_t dec) {
4342
return atomic_fetch_add(ptr, -(dec));
4443
}
45-
static bool atomic_compare_exchange_strong(atomic_int* ptr, atomic_int* expected, int desired) {
46-
int old_value = InterlockedCompareExchange((LONG*)ptr, desired, *expected);
44+
static bool atomic_compare_exchange_strong(atomic_int* ptr, atomic_int* expected, intptr_t desired) {
45+
intptr_t old_value = InterlockedCompareExchange64(ptr, desired, *expected);
4746
bool success = (old_value == *expected);
4847
if (!success) {
4948
*expected = old_value;

0 commit comments

Comments
 (0)