mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
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.
This commit is contained in:
parent
13addd2bbd
commit
f366e21504
5 changed files with 68 additions and 10 deletions
|
|
@ -360,6 +360,8 @@ _Py_atomic_load_ssize_relaxed(const Py_ssize_t *obj);
|
|||
static inline void *
|
||||
_Py_atomic_load_ptr_relaxed(const void *obj);
|
||||
|
||||
static inline unsigned long long
|
||||
_Py_atomic_load_ullong_relaxed(const unsigned long long *obj);
|
||||
|
||||
// --- _Py_atomic_store ------------------------------------------------------
|
||||
// Atomically performs `*obj = value` (sequential consistency)
|
||||
|
|
@ -452,6 +454,10 @@ _Py_atomic_store_ptr_relaxed(void *obj, void *value);
|
|||
static inline void
|
||||
_Py_atomic_store_ssize_relaxed(Py_ssize_t *obj, Py_ssize_t value);
|
||||
|
||||
static inline void
|
||||
_Py_atomic_store_ullong_relaxed(unsigned long long *obj,
|
||||
unsigned long long value);
|
||||
|
||||
|
||||
// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue