Skip to content

Commit 5b6e5c8

Browse files
committed
feat: more often check for interrupts in status iterator
1 parent 3b53982 commit 5b6e5c8

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

gix/src/status/iter/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,22 @@ impl Iterator for Iter {
238238
#[cfg(feature = "parallel")]
239239
loop {
240240
let (rx, _join_worktree, _join_tree) = self.rx_and_join.as_ref()?;
241-
match rx.recv().ok() {
242-
Some(item) => {
241+
match rx.recv_timeout(std::time::Duration::from_millis(25)) {
242+
Ok(item) => {
243243
if let Some(item) = self.maybe_keep_index_change(item) {
244244
break Some(Ok(item));
245245
}
246246
continue;
247247
}
248-
None => {
248+
// NOTE: this isn't necessary when index::from-tree also supports interrupts. As it stands,
249+
// on big repositories it can go up to 500ms which aren't interruptible, so this is another
250+
// way to not wait for this. Once it can be interrupted, this won't be needed anymore.
251+
Err(std::sync::mpsc::RecvTimeoutError::Timeout) => {
252+
if self.should_interrupt.load(Ordering::SeqCst) {
253+
return None;
254+
}
255+
}
256+
Err(std::sync::mpsc::RecvTimeoutError::Disconnected) => {
249257
let (_rx, worktree_handle, tree_handle) = self.rx_and_join.take()?;
250258
let tree_index = if let Some(handle) = tree_handle {
251259
match handle.join().expect("no panic") {

gix/src/util.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,10 @@ pub fn parallel_iter_drop<T, U, V>(
7575
return;
7676
}
7777
};
78-
// Wait until there is time to respond before we undo the change.
79-
if let Some(handle) = maybe_handle {
80-
handle.join().ok();
81-
}
82-
handle.join().ok();
78+
// Do not for the remaining threads. Everything but index-from-tree is interruptible, and that wouldn't
79+
// take very long even with huge trees.
80+
// If this every becomes a problem, just make `index::from-tree` interruptible, and keep waiting for handles here.
81+
drop((maybe_handle, handle));
8382
undo.fetch_update(
8483
std::sync::atomic::Ordering::SeqCst,
8584
std::sync::atomic::Ordering::SeqCst,

0 commit comments

Comments
 (0)