diff options
author | Victor Stinner <vstinner@python.org> | 2025-01-24 10:25:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-24 10:25:24 (GMT) |
commit | c005ea4951581bd5da7594f29594c9c840ec2fa5 (patch) | |
tree | 8cb74415e3f3e8f673f5cf7ff6f7573326667251 /Python/tracemalloc.c | |
parent | 36bb22993307b25593237a1022790d329b7c75e0 (diff) | |
download | cpython-c005ea4951581bd5da7594f29594c9c840ec2fa5.zip cpython-c005ea4951581bd5da7594f29594c9c840ec2fa5.tar.gz cpython-c005ea4951581bd5da7594f29594c9c840ec2fa5.tar.bz2 |
gh-129185: Use PyMutex in tracemalloc (#129246)
Diffstat (limited to 'Python/tracemalloc.c')
-rw-r--r-- | Python/tracemalloc.c | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/Python/tracemalloc.c b/Python/tracemalloc.c index 2065101..d27c2f9 100644 --- a/Python/tracemalloc.c +++ b/Python/tracemalloc.c @@ -3,6 +3,7 @@ #include "pycore_gc.h" // PyGC_Head #include "pycore_hashtable.h" // _Py_hashtable_t #include "pycore_initconfig.h" // _PyStatus_NO_MEMORY() +#include "pycore_lock.h" // PyMutex_LockFlags() #include "pycore_object.h" // _PyType_PreHeaderSize() #include "pycore_pymem.h" // _Py_tracemalloc_config #include "pycore_runtime.h" // _Py_ID() @@ -37,8 +38,8 @@ static int _PyTraceMalloc_TraceRef(PyObject *op, PyRefTracerEvent event, the GIL held from PyMem_RawFree(). It cannot acquire the lock because it would introduce a deadlock in _PyThreadState_DeleteCurrent(). */ #define tables_lock _PyRuntime.tracemalloc.tables_lock -#define TABLES_LOCK() PyThread_acquire_lock(tables_lock, 1) -#define TABLES_UNLOCK() PyThread_release_lock(tables_lock) +#define TABLES_LOCK() PyMutex_LockFlags(&tables_lock, _Py_LOCK_DONT_DETACH) +#define TABLES_UNLOCK() PyMutex_Unlock(&tables_lock) #define DEFAULT_DOMAIN 0 @@ -741,13 +742,6 @@ _PyTraceMalloc_Init(void) return _PyStatus_NO_MEMORY(); } - if (tables_lock == NULL) { - tables_lock = PyThread_allocate_lock(); - if (tables_lock == NULL) { - return _PyStatus_NO_MEMORY(); - } - } - tracemalloc_filenames = hashtable_new(hashtable_hash_pyobject, hashtable_compare_unicode, tracemalloc_clear_filename, NULL); @@ -792,11 +786,6 @@ tracemalloc_deinit(void) _Py_hashtable_destroy(tracemalloc_tracebacks); _Py_hashtable_destroy(tracemalloc_filenames); - if (tables_lock != NULL) { - PyThread_free_lock(tables_lock); - tables_lock = NULL; - } - PyThread_tss_delete(&tracemalloc_reentrant_key); } |