From f6f809544053519af9f24245ea3b61ad74d1d38d Mon Sep 17 00:00:00 2001 From: Janis Date: Fri, 20 Jun 2025 12:24:13 +0200 Subject: [PATCH] remove with_in/with functions from WorkerThread (replaced by run_in_*) --- src/praetor/mod.rs | 47 +++------------------------------------------- 1 file changed, 3 insertions(+), 44 deletions(-) diff --git a/src/praetor/mod.rs b/src/praetor/mod.rs index 55c9e08..d6fcc59 100644 --- a/src/praetor/mod.rs +++ b/src/praetor/mod.rs @@ -1034,7 +1034,7 @@ use parking_lot::{Condvar, Mutex}; use parking_lot_core::SpinWait; use util::{DropGuard, SendPtr}; -use crate::latch::{AtomicLatch, LatchRef, NopLatch, Probe}; +use crate::latch::{AtomicLatch, LatchRef, NopLatch}; #[derive(Debug, Default)] pub struct JobCounter { @@ -1144,46 +1144,6 @@ impl WorkerThread { } } - fn with_in T>(ctx: &Arc, 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: F) -> T { - Self::with_in(Context::global(), f) - } - /// sets the thread-local worker to this. unsafe fn set_current(this: *const WorkerThread) { WORKER.with(|ptr| unsafe { @@ -1299,7 +1259,7 @@ impl WorkerThread { while !pred() { let mut guard = self.context.shared.lock(); - let mut spin = SpinWait::new(); + let mut _spin = SpinWait::new(); match guard.pop_job() { Some(job) => { @@ -1488,7 +1448,7 @@ impl<'scope> Scope<'scope> { F: Future + Send + 'scope, T: Send + 'scope, { - WorkerThread::with_in(&self.context, |worker| { + self.context.run_in_worker(|worker| { self.job_counter.increment(); let this = SendPtr::new_const(&self.job_counter).unwrap(); @@ -1500,7 +1460,6 @@ impl<'scope> Scope<'scope> { future.await }; - let this = SendPtr::new_const(self).unwrap(); let schedule = move |runnable: Runnable| { #[repr(align(8))] unsafe fn harness(this: *const (), job: *const Job) {