summaryrefslogtreecommitdiffstats
path: root/Include/cpython/pyatomic_msc.h
diff options
context:
space:
mode:
authormpage <mpage@meta.com>2024-02-16 18:29:25 (GMT)
committerGitHub <noreply@github.com>2024-02-16 18:29:25 (GMT)
commitf366e215044e348659df814c27bf70e78907df21 (patch)
tree046a35e45d76f4db71825d63849009912fce0ea0 /Include/cpython/pyatomic_msc.h
parent13addd2bbdcbf96c5ea26a0f425c049f1b71e945 (diff)
downloadcpython-f366e215044e348659df814c27bf70e78907df21.zip
cpython-f366e215044e348659df814c27bf70e78907df21.tar.gz
cpython-f366e215044e348659df814c27bf70e78907df21.tar.bz2
gh-114271: Make `thread._rlock` thread-safe in free-threaded builds (#115102)
The ID of the owning thread (`rlock_owner`) may be accessed by multiple threads without holding the underlying lock; relaxed atomics are used in place of the previous loads/stores. The number of times that the lock has been acquired (`rlock_count`) is only ever accessed by the thread that holds the lock; we do not need to use atomics to access it.
Diffstat (limited to 'Include/cpython/pyatomic_msc.h')
-rw-r--r--Include/cpython/pyatomic_msc.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/Include/cpython/pyatomic_msc.h b/Include/cpython/pyatomic_msc.h
index b5c1ec9..6ab6401 100644
--- a/Include/cpython/pyatomic_msc.h
+++ b/Include/cpython/pyatomic_msc.h
@@ -712,6 +712,12 @@ _Py_atomic_load_ptr_relaxed(const void *obj)
return *(void * volatile *)obj;
}
+static inline unsigned long long
+_Py_atomic_load_ullong_relaxed(const unsigned long long *obj)
+{
+ return *(volatile unsigned long long *)obj;
+}
+
// --- _Py_atomic_store ------------------------------------------------------
@@ -886,6 +892,14 @@ _Py_atomic_store_ssize_relaxed(Py_ssize_t *obj, Py_ssize_t value)
*(volatile Py_ssize_t *)obj = value;
}
+static inline void
+_Py_atomic_store_ullong_relaxed(unsigned long long *obj,
+ unsigned long long value)
+{
+ *(volatile unsigned long long *)obj = value;
+}
+
+
// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------
static inline void *