remove with_in/with functions from WorkerThread (replaced by run_in_*)
This commit is contained in:
parent
940c681222
commit
f6f8095440
|
@ -1034,7 +1034,7 @@ use parking_lot::{Condvar, Mutex};
|
||||||
use parking_lot_core::SpinWait;
|
use parking_lot_core::SpinWait;
|
||||||
use util::{DropGuard, SendPtr};
|
use util::{DropGuard, SendPtr};
|
||||||
|
|
||||||
use crate::latch::{AtomicLatch, LatchRef, NopLatch, Probe};
|
use crate::latch::{AtomicLatch, LatchRef, NopLatch};
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct JobCounter {
|
pub struct JobCounter {
|
||||||
|
@ -1144,46 +1144,6 @@ impl WorkerThread {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_in<T, F: FnOnce(&WorkerThread) -> T>(ctx: &Arc<Context>, f: F) -> T {
|
|
||||||
let mut _guard = None;
|
|
||||||
|
|
||||||
let worker = match Self::current_ref() {
|
|
||||||
Some(current) if Arc::ptr_eq(¤t.context, ctx) => current,
|
|
||||||
Some(_) => {
|
|
||||||
// this thread's worker isn't in the same threadpool as us:
|
|
||||||
// - create a new worker in our threadpool and set it as the
|
|
||||||
// current, then make sure to drop that worker when we're done
|
|
||||||
// and replace the old worker.
|
|
||||||
_guard = Some(Self::drop_current_guard(unsafe { Self::unset_current() }));
|
|
||||||
|
|
||||||
let current = Box::into_raw(Box::new(Self::new_in(ctx.clone())));
|
|
||||||
unsafe {
|
|
||||||
Self::set_current(current.cast_const());
|
|
||||||
&*current
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
let current = Box::into_raw(Box::new(Self::new_in(ctx.clone())));
|
|
||||||
|
|
||||||
// drop the newly created worker thread once we're done.
|
|
||||||
_guard = Some(Self::drop_current_guard(None));
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
Self::set_current(current.cast_const());
|
|
||||||
|
|
||||||
&*current
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let t = f(worker);
|
|
||||||
t
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn with<T, F: FnOnce(&WorkerThread) -> T>(f: F) -> T {
|
|
||||||
Self::with_in(Context::global(), f)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// sets the thread-local worker to this.
|
/// sets the thread-local worker to this.
|
||||||
unsafe fn set_current(this: *const WorkerThread) {
|
unsafe fn set_current(this: *const WorkerThread) {
|
||||||
WORKER.with(|ptr| unsafe {
|
WORKER.with(|ptr| unsafe {
|
||||||
|
@ -1299,7 +1259,7 @@ impl WorkerThread {
|
||||||
|
|
||||||
while !pred() {
|
while !pred() {
|
||||||
let mut guard = self.context.shared.lock();
|
let mut guard = self.context.shared.lock();
|
||||||
let mut spin = SpinWait::new();
|
let mut _spin = SpinWait::new();
|
||||||
|
|
||||||
match guard.pop_job() {
|
match guard.pop_job() {
|
||||||
Some(job) => {
|
Some(job) => {
|
||||||
|
@ -1488,7 +1448,7 @@ impl<'scope> Scope<'scope> {
|
||||||
F: Future<Output = T> + Send + 'scope,
|
F: Future<Output = T> + Send + 'scope,
|
||||||
T: Send + 'scope,
|
T: Send + 'scope,
|
||||||
{
|
{
|
||||||
WorkerThread::with_in(&self.context, |worker| {
|
self.context.run_in_worker(|worker| {
|
||||||
self.job_counter.increment();
|
self.job_counter.increment();
|
||||||
|
|
||||||
let this = SendPtr::new_const(&self.job_counter).unwrap();
|
let this = SendPtr::new_const(&self.job_counter).unwrap();
|
||||||
|
@ -1500,7 +1460,6 @@ impl<'scope> Scope<'scope> {
|
||||||
future.await
|
future.await
|
||||||
};
|
};
|
||||||
|
|
||||||
let this = SendPtr::new_const(self).unwrap();
|
|
||||||
let schedule = move |runnable: Runnable| {
|
let schedule = move |runnable: Runnable| {
|
||||||
#[repr(align(8))]
|
#[repr(align(8))]
|
||||||
unsafe fn harness<T>(this: *const (), job: *const Job<T>) {
|
unsafe fn harness<T>(this: *const (), job: *const Job<T>) {
|
||||||
|
|
Loading…
Reference in a new issue