Skip to content

Commit 42f3f9e

Browse files
committed
Fix bug with TLV and scopes
1 parent fdc63f8 commit 42f3f9e

File tree

5 files changed

+13
-16
lines changed

5 files changed

+13
-16
lines changed

rayon-core/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ readme = "README.md"
1212
keywords = ["parallel", "thread", "concurrency", "join", "performance"]
1313
categories = ["concurrency"]
1414

15-
[features]
16-
default = ["tlv"]
17-
tlv = []
18-
1915
[dependencies]
2016
num_cpus = "1.2"
2117
libc = "0.2.16"

rayon-core/src/job.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::any::Any;
33
use std::cell::UnsafeCell;
44
use std::mem;
55
use unwind;
6-
#[cfg(feature = "tlv")]
76
use tlv;
87

98
pub enum JobResult<T> {
@@ -77,7 +76,6 @@ where
7776
pub latch: L,
7877
func: UnsafeCell<Option<F>>,
7978
result: UnsafeCell<JobResult<R>>,
80-
#[cfg(feature = "tlv")]
8179
tlv: usize,
8280
}
8381

@@ -92,7 +90,6 @@ where
9290
latch: latch,
9391
func: UnsafeCell::new(Some(func)),
9492
result: UnsafeCell::new(JobResult::None),
95-
#[cfg(feature = "tlv")]
9693
tlv: tlv::get(),
9794
}
9895
}
@@ -118,7 +115,6 @@ where
118115
{
119116
unsafe fn execute(this: *const Self) {
120117
let this = &*this;
121-
#[cfg(feature = "tlv")]
122118
tlv::set(this.tlv);
123119
let abort = unwind::AbortIfPanic;
124120
let func = (*this.func.get()).take().unwrap();
@@ -142,19 +138,17 @@ where
142138
BODY: FnOnce() + Send,
143139
{
144140
job: UnsafeCell<Option<BODY>>,
145-
#[cfg(feature = "tlv")]
146141
tlv: usize,
147142
}
148143

149144
impl<BODY> HeapJob<BODY>
150145
where
151146
BODY: FnOnce() + Send,
152147
{
153-
pub fn new(func: BODY) -> Self {
148+
pub fn new(tlv: usize, func: BODY) -> Self {
154149
HeapJob {
155150
job: UnsafeCell::new(Some(func)),
156-
#[cfg(feature = "tlv")]
157-
tlv: tlv::get(),
151+
tlv,
158152
}
159153
}
160154

@@ -173,7 +167,6 @@ where
173167
{
174168
unsafe fn execute(this: *const Self) {
175169
let this: Box<Self> = mem::transmute(this);
176-
#[cfg(feature = "tlv")]
177170
tlv::set(this.tlv);
178171
let job = (*this.job.get()).take().unwrap();
179172
job();

rayon-core/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ mod util;
5656
mod compile_fail;
5757
mod test;
5858

59-
#[cfg(feature = "tlv")]
6059
pub mod tlv;
6160

6261
#[cfg(rayon_unstable)]

rayon-core/src/scope/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::ptr;
1616
use std::sync::atomic::{AtomicPtr, Ordering};
1717
use std::sync::Arc;
1818
use unwind;
19+
use tlv;
1920

2021
mod internal;
2122
#[cfg(test)]
@@ -43,6 +44,7 @@ impl<'scope> ScopeBuilder<'scope> {
4344
panic: AtomicPtr::new(ptr::null_mut()),
4445
job_completed_latch: CountLatch::new(),
4546
marker: PhantomData,
47+
tlv: tlv::get(),
4648
});
4749
let scope = self.scope.as_ref().unwrap();
4850
let result = scope.execute_job_closure(move |_| op(scope));
@@ -78,6 +80,9 @@ pub struct Scope<'scope> {
7880
/// `Sync`, but it's still safe to let the `Scope` implement `Sync` because
7981
/// the closures are only *moved* across threads to be executed.
8082
marker: PhantomData<&'scope ()>,
83+
84+
/// The TLV at the scope's creation. Used to set the TLV for spawned jobs.
85+
tlv: usize,
8186
}
8287

8388
/// Create a "fork-join" scope `s` and invokes the closure with a
@@ -302,6 +307,7 @@ where
302307
panic: AtomicPtr::new(ptr::null_mut()),
303308
job_completed_latch: CountLatch::new(),
304309
marker: PhantomData,
310+
tlv: tlv::get(),
305311
};
306312
let result = scope.execute_job_closure(op);
307313
scope.steal_till_jobs_complete(owner_thread);
@@ -369,7 +375,10 @@ impl<'scope> Scope<'scope> {
369375
{
370376
unsafe {
371377
self.job_completed_latch.increment();
372-
let job_ref = Box::new(HeapJob::new(move || self.execute_job(body))).as_job_ref();
378+
let job_ref = Box::new(HeapJob::new(
379+
self.tlv,
380+
move || self.execute_job(body),
381+
)).as_job_ref();
373382

374383
// Since `Scope` implements `Sync`, we can't be sure
375384
// that we're still in a thread of this pool, so we

rayon-core/src/spawn/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ where
6868
// executed. This ref is decremented at the (*) below.
6969
registry.increment_terminate_count();
7070

71-
let async_job = Box::new(HeapJob::new({
71+
let async_job = Box::new(HeapJob::new(0, {
7272
let registry = registry.clone();
7373
move || {
7474
match unwind::halt_unwinding(func) {

0 commit comments

Comments
 (0)