Skip to content

Commit 408e44b

Browse files
committed
Make _LOAD_ATTR_INSTANCE_VALUE thread-safe
- Use atomic load for value - Use _Py_TryIncrefCompareStackRef for incref
1 parent 3b2c220 commit 408e44b

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

Python/bytecodes.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2142,12 +2142,18 @@ dummy_func(
21422142
split op(_LOAD_ATTR_INSTANCE_VALUE, (offset/1, owner -- attr, null if (oparg & 1))) {
21432143
PyObject *owner_o = PyStackRef_AsPyObjectBorrow(owner);
21442144
PyObject **value_ptr = (PyObject**)(((char *)owner_o) + offset);
2145-
PyObject *attr_o = *value_ptr;
2145+
PyObject *attr_o = FT_ATOMIC_LOAD_PTR_ACQUIRE(*value_ptr);
21462146
DEOPT_IF(attr_o == NULL);
2147-
STAT_INC(LOAD_ATTR, hit);
2147+
#ifdef Py_GIL_DISABLED
2148+
if (!_Py_TryIncrefCompareStackRef(value_ptr, attr_o, &attr)) {
2149+
DEOPT_IF(true);
2150+
}
2151+
#else
21482152
Py_INCREF(attr_o);
2149-
null = PyStackRef_NULL;
21502153
attr = PyStackRef_FromPyObjectSteal(attr_o);
2154+
#endif
2155+
STAT_INC(LOAD_ATTR, hit);
2156+
null = PyStackRef_NULL;
21512157
DECREF_INPUTS();
21522158
}
21532159

Python/executor_cases.c.h

Lines changed: 24 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)