diff --git a/src/praetor/mod.rs b/src/praetor/mod.rs index 974147a..7d38efc 100644 --- a/src/praetor/mod.rs +++ b/src/praetor/mod.rs @@ -1168,12 +1168,14 @@ impl WorkerThread { } #[allow(dead_code)] + #[inline(always)] fn current() -> Option> { - WORKER.with(|ptr| unsafe { *ptr.get() }) + unsafe { *WORKER.with(UnsafeCell::get) } } + #[inline(always)] fn current_ref<'a>() -> Option<&'a WorkerThread> { - WORKER.with(|ptr| unsafe { (&*ptr.get()).map(|ptr| ptr.as_ref()) }) + unsafe { (*WORKER.with(UnsafeCell::get)).map(|ptr| ptr.as_ref()) } } fn push_front(&self, job: &Job) { @@ -1263,6 +1265,7 @@ impl WorkerThread { } /// This function must be called from a worker thread. + #[inline] fn join_heartbeat(&self, a: A, b: B) -> (RA, RB) where RA: Send, @@ -1596,25 +1599,18 @@ impl<'scope> Scope<'scope> { A: FnOnce(&Self) -> RA + Send, B: FnOnce(&Self) -> RB + Send, { - #[inline(always)] - fn make_scope_closure<'scope, A, RA>( - this: SendPtr>, - a: A, - ) -> impl FnOnce() -> RA + use<'scope, RA, A> - where - A: FnOnce(&Scope<'scope>) -> RA + Send, - RA: Send, - { - let scope = unsafe { this.as_ref() }; - move || a(scope) - } - let worker = WorkerThread::current_ref().expect("join is run in workerthread."); let this = SendPtr::new_const(self).unwrap(); worker.join_heartbeat_every::<_, _, _, _, 64>( - make_scope_closure(this, a), - make_scope_closure(this, b), + { + let this = this; + move || a(unsafe { this.as_ref() }) + }, + { + let this = this; + move || b(unsafe { this.as_ref() }) + }, ) }