Move type-lock to per-interpreter lock to avoid heavy contention in i… · python/cpython@00aa303 · GitHub
Skip to content

Commit 00aa303

Browse files
committed
Move type-lock to per-interpreter lock to avoid heavy contention in interpreters test
1 parent 66ce5f5 commit 00aa303

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

Include/internal/pycore_typeobject.h

Lines changed: 1 addition & 1 deletion

Objects/typeobject.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,18 @@ class object "PyObject *" "&PyBaseObject_Type"
6060
// in odd behaviors w.r.t. running with the GIL as the outer type lock could
6161
// be released and reacquired during a subclass update if there's contention
6262
// on the subclass lock.
63+
#define TYPE_LOCK &PyInterpreterState_Get()->types.mutex
6364
#define BEGIN_TYPE_LOCK() \
6465
{ \
6566
_PyCriticalSection _cs; \
66-
_PyCriticalSection_Begin(&_cs, &_PyRuntime.types.type_mutex); \
67+
_PyCriticalSection_Begin(&_cs, TYPE_LOCK); \
6768

6869
#define END_TYPE_LOCK() \
6970
_PyCriticalSection_End(&_cs); \
7071
}
7172

7273
#define ASSERT_TYPE_LOCK_HELD() \
73-
_Py_CRITICAL_SECTION_ASSERT_MUTEX_LOCKED(&_PyRuntime.types.type_mutex)
74+
_Py_CRITICAL_SECTION_ASSERT_MUTEX_LOCKED(TYPE_LOCK)
7475

7576
#else
7677

Python/pystate.c

Lines changed: 2 additions & 1 deletion

0 commit comments

Comments
 (0)