run b first, then a

This commit is contained in:
Janis 2025-02-20 20:15:40 +01:00
parent c3804c8930
commit 37e8a6e721

View file

@ -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<NonNull<Job>> {
let head_link = unsafe { self.head.link_mut() };
@ -861,6 +861,7 @@ impl Scope {
fn pop_back(&self) -> Option<NonNull<Job>> {
unsafe { self.queue.as_mut_unchecked().pop_back() }
}
#[allow(dead_code)]
fn pop_front(&self) -> Option<NonNull<Job>> {
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::<RB>(unsafe {
mem::transmute::<Pin<&Job<()>>, Pin<&Job<RB>>>(job.as_ref())
match self.wait_until::<RA>(unsafe {
mem::transmute::<Pin<&Job<()>>, Pin<&Job<RA>>>(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)
}