Skip to content

Commit

Permalink
Fix _InterlockedCompareExchange64 calls on MSVC x86
Browse files Browse the repository at this point in the history
  • Loading branch information
colesbury committed Aug 22, 2023
1 parent d70e8ae commit 927430d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Include/cpython/pyatomic_msc.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ _Py_atomic_add_int64(volatile int64_t *address, int64_t value)
for (;;) {
int64_t old_value = *address;
int64_t new_value = old_value + value;
if (_InterlockedCompareExchange64((volatile __int64*)address, (__int64)new_value, (__int64)old_value)) {
if (old_value == _InterlockedCompareExchange64((volatile __int64*)address, (__int64)new_value, (__int64)old_value)) {
return old_value;
}
}
Expand Down Expand Up @@ -230,7 +230,7 @@ _Py_atomic_exchange_int64(volatile int64_t *address, int64_t value)
for (;;) {
int64_t old_value = *address;
int64_t new_value = value;
if (_InterlockedCompareExchange64((volatile __int64*)address, (__int64)new_value, (__int64)old_value)) {
if (old_value == _InterlockedCompareExchange64((volatile __int64*)address, (__int64)new_value, (__int64)old_value)) {
return old_value;
}
}
Expand Down Expand Up @@ -322,7 +322,7 @@ _Py_atomic_and_uint64(volatile uint64_t *address, uint64_t value)
for (;;) {
uint64_t old_value = *address;
uint64_t new_value = old_value & value;
if (_InterlockedCompareExchange64((volatile __int64*)address, (__int64)new_value, (__int64)old_value)) {
if (old_value == _InterlockedCompareExchange64((volatile __int64*)address, (__int64)new_value, (__int64)old_value)) {
return old_value;
}
}
Expand Down Expand Up @@ -366,7 +366,7 @@ _Py_atomic_or_uint64(volatile uint64_t *address, uint64_t value)
for (;;) {
uint64_t old_value = *address;
uint64_t new_value = old_value | value;
if (_InterlockedCompareExchange64((volatile __int64*)address, (__int64)new_value, (__int64)old_value)) {
if (old_value == _InterlockedCompareExchange64((volatile __int64*)address, (__int64)new_value, (__int64)old_value)) {
return old_value;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/_testcapi/pyatomic.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ static PyObject * \
test_atomic_add_##suffix(PyObject *self, PyObject *obj) { \
dtype x = 0; \
assert(_Py_atomic_add_##suffix(&x, 1) == 0); \
assert("a" && x == 1); \
assert(x == 1); \
assert(_Py_atomic_add_##suffix(&x, 2) == 1); \
assert(x == 3); \
assert(_Py_atomic_add_##suffix(&x, -2) == 3); \
assert("b" && x == 1); \
assert(x == 1); \
assert(_Py_atomic_add_##suffix(&x, -1) == 1); \
assert(x == 0); \
assert(_Py_atomic_add_##suffix(&x, -1) == 0); \
Expand Down

0 comments on commit 927430d

Please sign in to comment.