diff options
author | Sam Gross <colesbury@gmail.com> | 2024-11-26 21:46:06 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-26 16:46:06 -0500 |
commit | 71ede1142ddad2d31cc966b8fe4a5aff664f4d53 (patch) | |
tree | c8e17fd89be977bf04ffd1c01b352c4bbcb191f5 /Python/executor_cases.c.h | |
parent | f0d3f10c43c9029378adba11a65b3d1287e4be32 (diff) | |
download | cpython-71ede1142ddad2d31cc966b8fe4a5aff664f4d53.tar.gz cpython-71ede1142ddad2d31cc966b8fe4a5aff664f4d53.zip |
gh-115999: Add free-threaded specialization for `STORE_SUBSCR` (#127169)
The specialization only depends on the type, so no special thread-safety
considerations there.
STORE_SUBSCR_LIST_INT needs to lock the list before modifying it.
`_PyDict_SetItem_Take2` already internally locks the dictionary using a
critical section.
Diffstat (limited to 'Python/executor_cases.c.h')
-rw-r--r-- | Python/executor_cases.c.h | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 5af970ec4ae..d46412a1933 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -1235,15 +1235,23 @@ JUMP_TO_JUMP_TARGET(); } Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0]; - // Ensure index < len(list) - if (index >= PyList_GET_SIZE(list)) { + if (!LOCK_OBJECT(list)) { UOP_STAT_INC(uopcode, miss); JUMP_TO_JUMP_TARGET(); } + // Ensure index < len(list) + if (index >= PyList_GET_SIZE(list)) { + UNLOCK_OBJECT(list); + if (true) { + UOP_STAT_INC(uopcode, miss); + JUMP_TO_JUMP_TARGET(); + } + } STAT_INC(STORE_SUBSCR, hit); PyObject *old_value = PyList_GET_ITEM(list, index); PyList_SET_ITEM(list, index, PyStackRef_AsPyObjectSteal(value)); assert(old_value != NULL); + UNLOCK_OBJECT(list); // unlock before decrefs! Py_DECREF(old_value); PyStackRef_CLOSE_SPECIALIZED(sub_st, (destructor)PyObject_Free); PyStackRef_CLOSE(list_st); |