3
3
#include "pycore_gc.h" // PyGC_Head
4
4
#include "pycore_hashtable.h" // _Py_hashtable_t
5
5
#include "pycore_initconfig.h" // _PyStatus_NO_MEMORY()
6
+ #include "pycore_lock.h" // PyMutex_LockFlags()
6
7
#include "pycore_object.h" // _PyType_PreHeaderSize()
7
8
#include "pycore_pymem.h" // _Py_tracemalloc_config
8
9
#include "pycore_runtime.h" // _Py_ID()
@@ -37,8 +38,8 @@ static int _PyTraceMalloc_TraceRef(PyObject *op, PyRefTracerEvent event,
37
38
the GIL held from PyMem_RawFree(). It cannot acquire the lock because it
38
39
would introduce a deadlock in _PyThreadState_DeleteCurrent(). */
39
40
#define tables_lock _PyRuntime.tracemalloc.tables_lock
40
- #define TABLES_LOCK () PyThread_acquire_lock( tables_lock, 1 )
41
- #define TABLES_UNLOCK () PyThread_release_lock( tables_lock)
41
+ #define TABLES_LOCK () PyMutex_LockFlags(& tables_lock, _Py_LOCK_DONT_DETACH )
42
+ #define TABLES_UNLOCK () PyMutex_Unlock(& tables_lock)
42
43
43
44
44
45
#define DEFAULT_DOMAIN 0
@@ -741,13 +742,6 @@ _PyTraceMalloc_Init(void)
741
742
return _PyStatus_NO_MEMORY ();
742
743
}
743
744
744
- if (tables_lock == NULL ) {
745
- tables_lock = PyThread_allocate_lock ();
746
- if (tables_lock == NULL ) {
747
- return _PyStatus_NO_MEMORY ();
748
- }
749
- }
750
-
751
745
tracemalloc_filenames = hashtable_new (hashtable_hash_pyobject ,
752
746
hashtable_compare_unicode ,
753
747
tracemalloc_clear_filename , NULL );
@@ -792,11 +786,6 @@ tracemalloc_deinit(void)
792
786
_Py_hashtable_destroy (tracemalloc_tracebacks );
793
787
_Py_hashtable_destroy (tracemalloc_filenames );
794
788
795
- if (tables_lock != NULL ) {
796
- PyThread_free_lock (tables_lock );
797
- tables_lock = NULL ;
798
- }
799
-
800
789
PyThread_tss_delete (& tracemalloc_reentrant_key );
801
790
}
802
791
0 commit comments