mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-124218: Use per-thread reference counting for globals and builtins (#125713)
Use per-thread refcounting for the reference from function objects to the globals and builtins dictionaries.
This commit is contained in:
parent
d880c83ff7
commit
9b0bfba2a2
8 changed files with 115 additions and 11 deletions
|
|
@ -1636,6 +1636,24 @@ _PyDict_MaybeUntrack(PyObject *op)
|
|||
_PyObject_GC_UNTRACK(op);
|
||||
}
|
||||
|
||||
void
|
||||
_PyDict_EnablePerThreadRefcounting(PyObject *op)
|
||||
{
|
||||
assert(PyDict_Check(op));
|
||||
#ifdef Py_GIL_DISABLED
|
||||
Py_ssize_t id = _PyObject_AssignUniqueId(op);
|
||||
if ((uint64_t)id >= (uint64_t)DICT_UNIQUE_ID_MAX) {
|
||||
_PyObject_ReleaseUniqueId(id);
|
||||
return;
|
||||
}
|
||||
|
||||
PyDictObject *mp = (PyDictObject *)op;
|
||||
assert((mp->_ma_watcher_tag >> DICT_UNIQUE_ID_SHIFT) == 0);
|
||||
// Plus 1 so that _ma_watcher_tag=0 represents an unassigned id
|
||||
mp->_ma_watcher_tag += ((uint64_t)id + 1) << DICT_UNIQUE_ID_SHIFT;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline int
|
||||
is_unusable_slot(Py_ssize_t ix)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue