run b first, then a
This commit is contained in:
parent
c3804c8930
commit
37e8a6e721
|
@ -214,7 +214,6 @@ mod job {
|
||||||
pub fn new(value: T) -> Self {
|
pub fn new(value: T) -> Self {
|
||||||
let inline = Self::is_inline();
|
let inline = Self::is_inline();
|
||||||
|
|
||||||
// SAFETY: we know the box is allocated if state was `Pending`.
|
|
||||||
if inline {
|
if inline {
|
||||||
let this = MaybeUninit::new(Self(MaybeUninit::uninit()));
|
let this = MaybeUninit::new(Self(MaybeUninit::uninit()));
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -331,6 +330,7 @@ mod job {
|
||||||
elem_link.prev = Some(self.tail());
|
elem_link.prev = Some(self.tail());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn pop_front(&mut self) -> Option<NonNull<Job>> {
|
pub fn pop_front(&mut self) -> Option<NonNull<Job>> {
|
||||||
let head_link = unsafe { self.head.link_mut() };
|
let head_link = unsafe { self.head.link_mut() };
|
||||||
|
|
||||||
|
@ -861,6 +861,7 @@ impl Scope {
|
||||||
fn pop_back(&self) -> Option<NonNull<Job>> {
|
fn pop_back(&self) -> Option<NonNull<Job>> {
|
||||||
unsafe { self.queue.as_mut_unchecked().pop_back() }
|
unsafe { self.queue.as_mut_unchecked().pop_back() }
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
fn pop_front(&self) -> Option<NonNull<Job>> {
|
fn pop_front(&self) -> Option<NonNull<Job>> {
|
||||||
unsafe { self.queue.as_mut_unchecked().pop_front() }
|
unsafe { self.queue.as_mut_unchecked().pop_front() }
|
||||||
}
|
}
|
||||||
|
@ -895,7 +896,7 @@ impl Scope {
|
||||||
let count = self.join_count.get();
|
let count = self.join_count.get();
|
||||||
self.join_count.set(count.wrapping_add(1) % TIMES);
|
self.join_count.set(count.wrapping_add(1) % TIMES);
|
||||||
|
|
||||||
if count == 1 {
|
if count == 0 {
|
||||||
self.join_heartbeat(a, b)
|
self.join_heartbeat(a, b)
|
||||||
} else {
|
} else {
|
||||||
self.join_seq(a, b)
|
self.join_seq(a, b)
|
||||||
|
@ -909,31 +910,31 @@ impl Scope {
|
||||||
A: FnOnce() -> RA + Send,
|
A: FnOnce() -> RA + Send,
|
||||||
B: FnOnce() -> RB + 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());
|
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 {
|
unsafe {
|
||||||
job.unlink();
|
job.unlink();
|
||||||
}
|
}
|
||||||
|
|
||||||
self.tick();
|
self.tick();
|
||||||
unsafe { b.unwrap()() }
|
unsafe { a.unwrap()() }
|
||||||
} else {
|
} else {
|
||||||
match self.wait_until::<RB>(unsafe {
|
match self.wait_until::<RA>(unsafe {
|
||||||
mem::transmute::<Pin<&Job<()>>, Pin<&Job<RB>>>(job.as_ref())
|
mem::transmute::<Pin<&Job<()>>, Pin<&Job<RA>>>(job.as_ref())
|
||||||
}) {
|
}) {
|
||||||
Some(Ok(t)) => t,
|
Some(Ok(t)) => t,
|
||||||
Some(Err(payload)) => std::panic::resume_unwind(payload),
|
Some(Err(payload)) => std::panic::resume_unwind(payload),
|
||||||
None => unsafe { b.unwrap()() },
|
None => unsafe { a.unwrap()() },
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
drop(b);
|
drop(a);
|
||||||
(ra, rb)
|
(ra, rb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue