Skip to content

Commit c0f08c2

Browse files
ngoldbaumepilys
andauthored
Implement locked iteration for PyList (#4789)
* implement locked iteration for PyList * fix limited API and PyPy support * fix formatting of safety docstrings * only define fold and rfold on not(feature = "nightly") * add missing try_fold implementation on nightly * Use split borrows for locked iteration for PyList Inline ListIterImpl implementations by using split borrows and destructuring let Self { .. } = self destructuring inside BoundListIterator impls. Signed-off-by: Manos Pitsidianakis <[email protected]> * use a function to do the split borrow * add changelog entries * fix clippy on limited API and PyPy * use a macro for the split borrow * add a test that mutates the list during a fold * enable next_unchecked on PyPy * fix incorrect docstring for locked_for_each * simplify borrows by adding BoundListIterator::with_critical_section * fix build on GIL-enabled and limited API builds * fix docs build on MSRV --------- Signed-off-by: Manos Pitsidianakis <[email protected]> Co-authored-by: Manos Pitsidianakis <[email protected]>
1 parent 4670203 commit c0f08c2

File tree

3 files changed

+454
-33
lines changed

3 files changed

+454
-33
lines changed

newsfragments/4789.added.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* Added `PyList::locked_for_each`, which is equivalent to `PyList::for_each` on
2+
the GIL-enabled build and uses a critical section to lock the list on the
3+
free-threaded build, similar to `PyDict::locked_for_each`.

newsfragments/4789.changed.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* Operations that process a PyList via an iterator now use a critical section
2+
on the free-threaded build to amortize synchronization cost and prevent race conditions.

0 commit comments

Comments
 (0)