inline workerthread::current
This commit is contained in:
parent
3730952cad
commit
3eec242097
|
@ -1168,12 +1168,14 @@ impl WorkerThread {
|
|||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[inline(always)]
|
||||
fn current() -> Option<NonNull<WorkerThread>> {
|
||||
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<T>(&self, job: &Job<T>) {
|
||||
|
@ -1263,6 +1265,7 @@ impl WorkerThread {
|
|||
}
|
||||
|
||||
/// This function must be called from a worker thread.
|
||||
#[inline]
|
||||
fn join_heartbeat<A, B, RA, RB>(&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<Scope<'scope>>,
|
||||
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() })
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue