Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
colesbury committed Aug 22, 2023
1 parent 51c4b93 commit 7bc94db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
12 changes: 11 additions & 1 deletion Include/pyatomic_msc.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,17 @@ _Py_atomic_exchange_int32(volatile int32_t *address, int32_t value)
static inline int64_t
_Py_atomic_exchange_int64(volatile int64_t *address, int64_t value)
{
#if defined(_M_X64) || defined(_M_ARM64)
return (int64_t)_InterlockedExchange64((volatile __int64*)address, (__int64)value);
#else
for (;;) {
int64_t old_value = *address;
int64_t new_value = value;
if (_InterlockedCompareExchange64((volatile __int64*)address, (__int64)new_value, (__int64)old_value)) {
return old_value;
}
}
#endif
}

static inline intptr_t
Expand Down Expand Up @@ -240,7 +250,7 @@ _Py_atomic_exchange_uintptr(volatile uintptr_t *address, uintptr_t value)
}

static inline Py_ssize_t
_Py_atomic_exchange_ssize(volatile Py_ssize_t *address, Py_ssize_t value);
_Py_atomic_exchange_ssize(volatile Py_ssize_t *address, Py_ssize_t value)
{
#if SIZEOF_SIZE_T == 8
return (Py_ssize_t)_InterlockedExchange64((volatile __int64*)address, (__int64)value);
Expand Down
16 changes: 7 additions & 9 deletions Modules/_testcapi/pyatomic.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,19 @@
static PyObject * \
test_atomic_add_##suffix(PyObject *self, PyObject *obj) { \
dtype x = 0; \
dtype y = 1; \
dtype z = 2; \
assert(_Py_atomic_add_##suffix(&x, y) == 0); \
assert(_Py_atomic_add_##suffix(&x, 1) == 0); \
assert("a" && x == 1); \
assert(_Py_atomic_add_##suffix(&x, z) == 1); \
assert(_Py_atomic_add_##suffix(&x, 2) == 1); \
assert(x == 3); \
assert(_Py_atomic_add_##suffix(&x, -z) == 3); \
assert(_Py_atomic_add_##suffix(&x, -2) == 3); \
assert("b" && x == 1); \
assert(_Py_atomic_add_##suffix(&x, -y) == 1); \
assert(_Py_atomic_add_##suffix(&x, -1) == 1); \
assert(x == 0); \
assert(_Py_atomic_add_##suffix(&x, -y) == 0); \
assert(_Py_atomic_add_##suffix(&x, -1) == 0); \
assert(x == (dtype)-1); \
assert(_Py_atomic_add_##suffix(&x, -z) == (dtype)-1); \
assert(_Py_atomic_add_##suffix(&x, -2) == (dtype)-1); \
assert(x == (dtype)-3); \
assert(_Py_atomic_add_##suffix(&x, z) == (dtype)-3); \
assert(_Py_atomic_add_##suffix(&x, 2) == (dtype)-3); \
assert(x == (dtype)-1); \
Py_RETURN_NONE; \
}
Expand Down

0 comments on commit 7bc94db

Please sign in to comment.