Skip to content

Commit 073b79b

Browse files
committed
Impl LatchProbe and Latch for &L where L: Latch.
1 parent 228dbf7 commit 073b79b

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
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<'a, L: 'a, F, R>
67+
pub(super) struct StackJob<L, F, R>
6868
where
6969
L: Latch + Sync,
7070
F: FnOnce(bool) -> R + Send,
7171
R: Send,
7272
{
73-
pub(super) latch: &'a mut L,
73+
pub(super) latch: L,
7474
func: UnsafeCell<Option<F>>,
7575
result: UnsafeCell<JobResult<R>>,
7676
}
7777

78-
impl<'a, L, F, R> StackJob<'a, L, F, R>
78+
impl<L, F, R> StackJob<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: &'a mut L) -> StackJob<'a, L, F, R> {
84+
pub(super) fn new(func: F, latch: L) -> StackJob<L, F, R> {
8585
StackJob {
8686
latch,
8787
func: UnsafeCell::new(Some(func)),
@@ -102,7 +102,7 @@ where
102102
}
103103
}
104104

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

rayon-core/src/join/mod.rs

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

123-
let mut latch = SpinLatch::new();
123+
let latch = SpinLatch::new();
124124

125125
// Create virtual wrapper for task b; this all has to be
126126
// done here so that the stack frame can keep it all live
127127
// long enough.
128-
let job_b = StackJob::new(|migrated| oper_b(FnContext::new(migrated)), &mut latch);
128+
let job_b = StackJob::new(|migrated| oper_b(FnContext::new(migrated)), &latch);
129129
let job_b_ref = job_b.as_job_ref();
130130
worker_thread.push(job_b_ref);
131131

rayon-core/src/latch.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl LockLatch {
8787
}
8888

8989
/// Resets this lock latch so it can be reused again.
90-
pub(super) fn reset(&mut self) {
90+
pub(super) fn reset(&self) {
9191
*self.m.lock().unwrap() = false;
9292
}
9393

@@ -191,3 +191,15 @@ impl<'a, L: Latch> Latch for TickleLatch<'a, L> {
191191
self.sleep.tickle(usize::MAX);
192192
}
193193
}
194+
195+
impl<'a, L> LatchProbe for &'a L where L: LatchProbe {
196+
fn probe(&self) -> bool {
197+
unimplemented!()
198+
}
199+
}
200+
201+
impl<'a, L> Latch for &'a L where L: Latch {
202+
fn set(&self) {
203+
unimplemented!()
204+
}
205+
}

rayon-core/src/registry.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::fmt;
1515
use std::hash::Hasher;
1616
use std::io;
1717
use std::mem;
18-
use std::ops::DerefMut;
18+
use std::ops::{Deref};
1919
use std::ptr;
2020
#[allow(deprecated)]
2121
use std::sync::atomic::ATOMIC_USIZE_INIT;
@@ -480,7 +480,8 @@ impl Registry {
480480
}
481481
}
482482
}
483-
483+
484+
484485
#[cold]
485486
unsafe fn in_worker_cold<OP, R>(&self, op: OP) -> R
486487
where
@@ -490,7 +491,7 @@ impl Registry {
490491
LOCK_LATCH.with(|l| {
491492
// This should not panic since the latch is thread local and we are in the `cold` path.
492493
// If `op` were to call another `ThreadPool::install` it would not end up here.
493-
let mut latch = l.borrow_mut();
494+
let latch = l.borrow();
494495

495496
// This thread isn't a member of *any* thread pool, so just block.
496497
debug_assert!(WorkerThread::current().is_null());
@@ -500,7 +501,7 @@ impl Registry {
500501
assert!(injected && !worker_thread.is_null());
501502
op(&*worker_thread, true)
502503
},
503-
latch.deref_mut(),
504+
latch.deref(),
504505
);
505506
self.inject(&[job.as_job_ref()]);
506507
job.latch.wait();
@@ -518,14 +519,14 @@ impl Registry {
518519
// This thread is a member of a different pool, so let it process
519520
// other work while waiting for this `op` to complete.
520521
debug_assert!(current_thread.registry().id() != self.id());
521-
let mut latch = TickleLatch::new(SpinLatch::new(), &current_thread.registry().sleep);
522+
let latch = TickleLatch::new(SpinLatch::new(), &current_thread.registry().sleep);
522523
let job = StackJob::new(
523524
|injected| {
524525
let worker_thread = WorkerThread::current();
525526
assert!(injected && !worker_thread.is_null());
526527
op(&*worker_thread, true)
527528
},
528-
&mut latch,
529+
&latch,
529530
);
530531
self.inject(&[job.as_job_ref()]);
531532
current_thread.wait_until(job.latch);

0 commit comments

Comments
 (0)