Skip to content

Commit

Permalink
Merge pull request #2 from dragostis/yield
Browse files Browse the repository at this point in the history
Replaced spinning with yield.
  • Loading branch information
dragostis authored Sep 13, 2024
2 parents e750e10 + c3967c1 commit 1d5e94f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
2 changes: 1 addition & 1 deletion benches/overhead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn no_overhead(bencher: Bencher, nodes: (usize, usize)) {
}

#[divan::bench(args = nodes())]
fn overhead(bencher: Bencher, nodes: (usize, usize)) {
fn spice_overhead(bencher: Bencher, nodes: (usize, usize)) {
fn sum(node: &Node, scope: &mut Scope<'_>) -> u64 {
let (left, right) = scope.join(
|s| node.left.as_deref().map(|n| sum(n, s)).unwrap_or_default(),
Expand Down
9 changes: 2 additions & 7 deletions src/job.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{
cell::{Cell, UnsafeCell},
hint,
mem::ManuallyDrop,
panic::{self, AssertUnwindSafe},
ptr::{self, NonNull},
Expand Down Expand Up @@ -63,9 +62,7 @@ impl<T> Future<T> {
_ => (),
}

// Spinning time should be short since the lock is held only to
// write the `Box<T>` and unpark this thread.
hint::spin_loop();
thread::yield_now();
}
}

Expand All @@ -82,9 +79,7 @@ impl<T> Future<T> {

match result {
Ok(_) => break,
// Spinning time should be short since the lock is held only to
// write the thread to `self.waiting_thread`.
Err(_) => hint::spin_loop(),
Err(_) => thread::yield_now(),
}
}

Expand Down

0 comments on commit 1d5e94f

Please sign in to comment.