Skip to content

Commit 11c64a6

Browse files
committed
Add _Py_IsOwnedByCurrentThread() special case for list_atomic_memmove
1 parent 97e8d13 commit 11c64a6

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Objects/listobject.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,12 @@ list_atomic_memmove(PyListObject *a, PyObject **dest, PyObject **src, Py_ssize_t
896896
#ifndef Py_GIL_DISABLED
897897
memmove(dest, src, n * sizeof(PyObject *));
898898
#else
899+
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(a);
900+
if (_Py_IsOwnedByCurrentThread((PyObject *)a) && !_PyObject_GC_IS_SHARED(a)) {
901+
// No other threads can read this list concurrently
902+
memmove(dest, src, n * sizeof(PyObject *));
903+
return;
904+
}
899905
if (dest < src) {
900906
for (Py_ssize_t i = 0; i != n; i++) {
901907
_Py_atomic_store_ptr_release(&dest[i], src[i]);

0 commit comments

Comments
 (0)