8000 gh-128100: Atomic dict load in _PyObject_GenericGetAttrWithDict by wrongnull · Pull Request #128297 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Implement atomic load and critical section in C code
  • Loading branch information
wrongnull committed Dec 26, 2024
commit c8ccd02bbcec0ae12409efcd7beececaa436281a
6 changes: 6 additions & 0 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1715,10 +1715,16 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name,
dict = (PyObject *)_PyObject_GetManagedDict(obj);
}
else {
Py_BEGIN_CRITICAL_SECTION(obj);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, we don't need to lock something if we're going to use one of the _Py_atomic APIs, and vice versa.

PyObject **dictptr = _PyObject_ComputedDictPointer(obj);
if (dictptr) {
#ifdef DISABLE_GIL
dict = (PyObject *)_Py_atomic_load_ptr(dictptr);
#else
dict = *dictptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is where the atomic load should be. (And, as Sam said in the issue, we want _Py_atomic_load_ptr_acquire instead of plain old _Py_atomic_load_ptr.)

#endif
}
Py_END_CRITICAL_SECTION();
}
}
if (dict != NULL) {
Expand Down
0