]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-111926: Make weakrefs thread-safe in free-threaded builds (#117168)
authormpage <mpage@meta.com>
Mon, 8 Apr 2024 14:58:38 +0000 (07:58 -0700)
committerGitHub <noreply@github.com>
Mon, 8 Apr 2024 14:58:38 +0000 (10:58 -0400)
commitdf7317904849a41d51db39d92c5d431a18e22637
treee7dddcb5006cb6f50b9f47477217043157a42e01
parente16062dd3428a5846344e0a8c6ee2f352d34ce1b
gh-111926: Make weakrefs thread-safe in free-threaded builds (#117168)

Most mutable data is protected by a striped lock that is keyed on the
referenced object's address. The weakref's hash is protected using the
weakref's per-object lock.

Note that this only affects free-threaded builds. Apart from some minor
refactoring, the added code is all either gated by `ifdef`s or is a no-op
(e.g. `Py_BEGIN_CRITICAL_SECTION`).
17 files changed:
Include/cpython/weakrefobject.h
Include/internal/pycore_interp.h
Include/internal/pycore_object.h
Include/internal/pycore_pyatomic_ft_wrappers.h
Include/internal/pycore_weakref.h
Lib/test/test_sys.py
Lib/test/test_weakref.py
Modules/_sqlite/blob.c
Modules/_sqlite/connection.c
Modules/_ssl.c
Modules/_ssl/debughelpers.c
Modules/_weakref.c
Modules/clinic/_weakref.c.h
Objects/dictobject.c
Objects/typeobject.c
Objects/weakrefobject.c
Python/pystate.c