gh-112050: Make collections.deque thread-safe in free-threaded builds (#113830)

Use critical sections to make deque methods that operate on mutable 
state thread-safe when the GIL is disabled. This is mostly accomplished
by using the @critical_section Argument Clinic directive, though there
are a few places where this was not possible and critical sections had
to be manually acquired/released.
This commit is contained in:
mpage 2024-02-15 00:22:47 -08:00 committed by GitHub
parent 474204765b
commit dc978f6ab6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 338 additions and 61 deletions

View file

@ -20,11 +20,13 @@ extern "C" {
#endif
#ifdef Py_GIL_DISABLED
#define FT_ATOMIC_LOAD_SSIZE(value) _Py_atomic_load_ssize(&value)
#define FT_ATOMIC_LOAD_SSIZE_RELAXED(value) \
_Py_atomic_load_ssize_relaxed(&value)
#define FT_ATOMIC_STORE_SSIZE_RELAXED(value, new_value) \
_Py_atomic_store_ssize_relaxed(&value, new_value)
#else
#define FT_ATOMIC_LOAD_SSIZE(value) value
#define FT_ATOMIC_LOAD_SSIZE_RELAXED(value) value
#define FT_ATOMIC_STORE_SSIZE_RELAXED(value, new_value) value = new_value
#endif