From 37e8a6e721b0d43a2480ad7747f9bac8808e0480 Mon Sep 17 00:00:00 2001 From: Janis Date: Thu, 20 Feb 2025 20:15:40 +0100 Subject: [PATCH] run b first, then a --- src/praetor/mod.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/praetor/mod.rs b/src/praetor/mod.rs index ae1999e..e3a0e5f 100644 --- a/src/praetor/mod.rs +++ b/src/praetor/mod.rs @@ -214,7 +214,6 @@ mod job { pub fn new(value: T) -> Self { let inline = Self::is_inline(); - // SAFETY: we know the box is allocated if state was `Pending`. if inline { let this = MaybeUninit::new(Self(MaybeUninit::uninit())); unsafe { @@ -331,6 +330,7 @@ mod job { elem_link.prev = Some(self.tail()); } + #[allow(dead_code)] pub fn pop_front(&mut self) -> Option> { let head_link = unsafe { self.head.link_mut() }; @@ -861,6 +861,7 @@ impl Scope { fn pop_back(&self) -> Option> { unsafe { self.queue.as_mut_unchecked().pop_back() } } + #[allow(dead_code)] fn pop_front(&self) -> Option> { unsafe { self.queue.as_mut_unchecked().pop_front() } } @@ -895,7 +896,7 @@ impl Scope { let count = self.join_count.get(); self.join_count.set(count.wrapping_add(1) % TIMES); - if count == 1 { + if count == 0 { self.join_heartbeat(a, b) } else { self.join_seq(a, b) @@ -909,31 +910,31 @@ impl Scope { A: FnOnce() -> RA + Send, B: FnOnce() -> RB + Send, { - let b = StackJob::new(b); + let a = StackJob::new(a); - let job = pin!(b.as_job()); + let job = pin!(a.as_job()); self.push_front(job.as_ref()); - let ra = a(); + let rb = b(); - let rb = if job.state() == JobState::Empty as u8 { + let ra = if job.state() == JobState::Empty as u8 { unsafe { job.unlink(); } self.tick(); - unsafe { b.unwrap()() } + unsafe { a.unwrap()() } } else { - match self.wait_until::(unsafe { - mem::transmute::>, Pin<&Job>>(job.as_ref()) + match self.wait_until::(unsafe { + mem::transmute::>, Pin<&Job>>(job.as_ref()) }) { Some(Ok(t)) => t, Some(Err(payload)) => std::panic::resume_unwind(payload), - None => unsafe { b.unwrap()() }, + None => unsafe { a.unwrap()() }, } }; - drop(b); + drop(a); (ra, rb) }