Skip to content

Commit 55f235f

Browse files
committed
Make StackJob take a &mut latch.
1 parent 481939b commit 55f235f

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

rayon-core/src/job.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,24 @@ impl JobRef {
6464
/// executes it need not free any heap data, the cleanup occurs when
6565
/// the stack frame is later popped. The function parameter indicates
6666
/// `true` if the job was stolen -- executed on a different thread.
67-
pub(super) struct StackJob<L, F, R>
67+
pub(super) struct StackJob<'a, L, F, R>
6868
where
6969
L: Latch + Sync,
7070
F: FnOnce(bool) -> R + Send,
7171
R: Send,
7272
{
73-
pub(super) latch: L,
73+
pub(super) latch: &'a mut L,
7474
func: UnsafeCell<Option<F>>,
7575
result: UnsafeCell<JobResult<R>>,
7676
}
7777

78-
impl<L, F, R> StackJob<L, F, R>
78+
impl<'a, L, F, R> StackJob<'a, L, F, R>
7979
where
8080
L: Latch + Sync,
8181
F: FnOnce(bool) -> R + Send,
8282
R: Send,
8383
{
84-
pub(super) fn new(func: F, latch: L) -> StackJob<L, F, R> {
84+
pub(super) fn new(func: F, latch: &'a mut L) -> StackJob<'a, L, F, R> {
8585
StackJob {
8686
latch,
8787
func: UnsafeCell::new(Some(func)),
@@ -102,7 +102,7 @@ where
102102
}
103103
}
104104

105-
impl<L, F, R> Job for StackJob<L, F, R>
105+
impl<'a, L, F, R> Job for StackJob<'a, L, F, R>
106106
where
107107
L: Latch + Sync,
108108
F: FnOnce(bool) -> R + Send,

rayon-core/src/join/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,12 @@ where
120120
worker: worker_thread.index()
121121
});
122122

123+
let mut latch = SpinLatch::new();
124+
123125
// Create virtual wrapper for task b; this all has to be
124126
// done here so that the stack frame can keep it all live
125127
// long enough.
126-
let job_b = StackJob::new(
127-
|migrated| oper_b(FnContext::new(migrated)),
128-
SpinLatch::new(),
129-
);
128+
let job_b = StackJob::new(|migrated| oper_b(FnContext::new(migrated)), &mut latch);
130129
let job_b_ref = job_b.as_job_ref();
131130
worker_thread.push(job_b_ref);
132131

@@ -165,7 +164,7 @@ where
165164
log!(LostJob {
166165
worker: worker_thread.index()
167166
});
168-
worker_thread.wait_until(&job_b.latch);
167+
worker_thread.wait_until(job_b.latch);
169168
debug_assert!(job_b.latch.probe());
170169
break;
171170
}

rayon-core/src/registry.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use latch::{CountLatch, Latch, LatchProbe, LockLatch, SpinLatch, TickleLatch};
99
use log::Event::*;
1010
use sleep::Sleep;
1111
use std::any::Any;
12-
use std::cell::Cell;
12+
use std::cell::{Cell, RefCell};
1313
use std::collections::hash_map::DefaultHasher;
1414
use std::fmt;
1515
use std::hash::Hasher;
@@ -486,6 +486,8 @@ impl Registry {
486486
OP: FnOnce(&WorkerThread, bool) -> R + Send,
487487
R: Send,
488488
{
489+
let mut latch = LockLatch::new();
490+
489491
// This thread isn't a member of *any* thread pool, so just block.
490492
debug_assert!(WorkerThread::current().is_null());
491493
let job = StackJob::new(
@@ -494,7 +496,7 @@ impl Registry {
494496
assert!(injected && !worker_thread.is_null());
495497
op(&*worker_thread, true)
496498
},
497-
LockLatch::new(),
499+
&mut latch,
498500
);
499501
self.inject(&[job.as_job_ref()]);
500502
job.latch.wait();
@@ -510,17 +512,17 @@ impl Registry {
510512
// This thread is a member of a different pool, so let it process
511513
// other work while waiting for this `op` to complete.
512514
debug_assert!(current_thread.registry().id() != self.id());
513-
let latch = TickleLatch::new(SpinLatch::new(), &current_thread.registry().sleep);
515+
let mut latch = TickleLatch::new(SpinLatch::new(), &current_thread.registry().sleep);
514516
let job = StackJob::new(
515517
|injected| {
516518
let worker_thread = WorkerThread::current();
517519
assert!(injected && !worker_thread.is_null());
518520
op(&*worker_thread, true)
519521
},
520-
latch,
522+
&mut latch,
521523
);
522524
self.inject(&[job.as_job_ref()]);
523-
current_thread.wait_until(&job.latch);
525+
current_thread.wait_until(job.latch);
524526
job.into_result()
525527
}
526528

0 commit comments

Comments
 (0)