Skip to content

Commit f65e87c

Browse files
committed
Improve comment for TYPE_LOCK.
1 parent 2af9e49 commit f65e87c

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

Objects/typeobject.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,28 @@ class object "PyObject *" "&PyBaseObject_Type"
6060

6161
#ifdef Py_GIL_DISABLED
6262

63-
// There's a global lock for types that ensures that the tp_version_tag is
64-
// correctly updated if the type is modified. This avoids having to take
65-
// additional locks while doing various subclass processing which may result
66-
// in odd behaviors w.r.t. running with the GIL as the outer type lock could
67-
// be released and reacquired during a subclass update if there's contention
68-
// on the subclass lock.
63+
// There's a global lock for types that ensures that tp_version_tag and
64+
// _spec_cache are correctly updated if the type is modified. This avoids
65+
// having to take additional locks while doing various subclass processing
66+
// which may result in odd behaviors w.r.t. running with the GIL as the outer
67+
// type lock could be released and reacquired during a subclass update if
68+
// there's contention on the subclass lock.
6969
//
7070
// Note that this lock does not protect when updating type slots or the
7171
// tp_flags member. Instead, we either ensure those updates are done before
7272
// the type has been revealed to other threads or we only do those updates
7373
// while the stop-the-world mechanism is active. The slots and flags are read
7474
// in many places without holding a lock and without atomics.
75-
//
75+
#define TYPE_LOCK &PyInterpreterState_Get()->types.mutex
76+
7677
// Since TYPE_LOCK is used as regular mutex, we must take special care about
7778
// potential re-entrant code paths. We use TYPE_LOCK_TID in debug builds to
7879
// ensure that we are not trying to re-acquire the mutex when it is already
7980
// held by the current thread. There are a couple cases when we release the
80-
// mutex, when we call functions that might re-enter.
81-
#define TYPE_LOCK &PyInterpreterState_Get()->types.mutex
82-
83-
// Used to check for correct use of the TYPE_LOCK mutex. It is a regular
84-
// mutex and does not support re-entrancy. If we already hold the lock and
85-
// try to acquire it again with the same thread, it is a bug on the code.
81+
// mutex, when we call functions that might re-enter. If we already hold the
82+
// lock and try to acquire it again with the same thread, it is a bug in the
83+
// code. We could just let it deadlock but having an assert failure gives
84+
// a more explicit error.
8685
#define TYPE_LOCK_TID &PyInterpreterState_Get()->types.mutex_tid
8786

8887
// Return true if the world is currently stopped.

0 commit comments

Comments
 (0)