Skip to content

Commit ba41dab

Browse files
committed
Reduce genericity in join wrappers
1 parent 249fbb9 commit ba41dab

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

rayon-core/src/job.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,14 @@ where
109109
R: Send,
110110
{
111111
unsafe fn execute(this: *const Self) {
112+
fn call<R>(func: impl FnOnce(bool) -> R) -> impl FnOnce() -> R {
113+
move || func(true)
114+
}
115+
112116
let this = &*this;
113117
let abort = unwind::AbortIfPanic;
114118
let func = (*this.func.get()).take().unwrap();
115-
(*this.result.get()) = match unwind::halt_unwinding(|| func(true)) {
119+
(*this.result.get()) = match unwind::halt_unwinding(call(func)) {
116120
Ok(x) => JobResult::Ok(x),
117121
Err(x) => JobResult::Panic(x),
118122
};

rayon-core/src/join/mod.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ where
9898
RA: Send,
9999
RB: Send,
100100
{
101-
join_context(|_| oper_a(), |_| oper_b())
101+
#[inline]
102+
fn call<R>(f: impl FnOnce() -> R) -> impl FnOnce(FnContext) -> R {
103+
move |_| f()
104+
}
105+
106+
join_context(call(oper_a), call(oper_b))
102107
}
103108

104109
/// Identical to `join`, except that the closures have a parameter
@@ -115,22 +120,30 @@ where
115120
RA: Send,
116121
RB: Send,
117122
{
123+
#[inline]
124+
fn call_a<R>(f: impl FnOnce(FnContext) -> R, injected: bool) -> impl FnOnce() -> R {
125+
move || f(FnContext::new(injected))
126+
}
127+
128+
#[inline]
129+
fn call_b<R>(f: impl FnOnce(FnContext) -> R) -> impl FnOnce(bool) -> R {
130+
move |migrated| f(FnContext::new(migrated))
131+
}
132+
118133
registry::in_worker(|worker_thread, injected| unsafe {
119134
log!(Join {
120135
worker: worker_thread.index()
121136
});
122137

123-
let latch = SpinLatch::new();
124-
125138
// Create virtual wrapper for task b; this all has to be
126139
// done here so that the stack frame can keep it all live
127140
// long enough.
128-
let job_b = StackJob::new(|migrated| oper_b(FnContext::new(migrated)), latch);
141+
let job_b = StackJob::new(call_b(oper_b), SpinLatch::new());
129142
let job_b_ref = job_b.as_job_ref();
130143
worker_thread.push(job_b_ref);
131144

132145
// Execute task a; hopefully b gets stolen in the meantime.
133-
let status_a = unwind::halt_unwinding(move || oper_a(FnContext::new(injected)));
146+
let status_a = unwind::halt_unwinding(call_a(oper_a, injected));
134147
let result_a = match status_a {
135148
Ok(v) => v,
136149
Err(err) => join_recover_from_panic(worker_thread, &job_b.latch, err),

0 commit comments

Comments
 (0)