From 5d228cd56470645d4e0d15ec0e891f19d07a0c9c Mon Sep 17 00:00:00 2001 From: Michael Hsu Date: Mon, 9 Jan 2023 10:31:49 -0800 Subject: [PATCH] rename related structs to be more clear --- crates/bevy_tasks/src/task_pool.rs | 7 ++++--- crates/bevy_tasks/src/thread_executor.rs | 16 ++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/crates/bevy_tasks/src/task_pool.rs b/crates/bevy_tasks/src/task_pool.rs index 0a9eb4feda640..a6ee72e44c2e0 100644 --- a/crates/bevy_tasks/src/task_pool.rs +++ b/crates/bevy_tasks/src/task_pool.rs @@ -11,7 +11,7 @@ use concurrent_queue::ConcurrentQueue; use futures_lite::{future, pin, FutureExt}; use crate::{ - thread_executor::{ThreadExecutor, ThreadSpawner}, + thread_executor::{ThreadExecutor, ThreadExecutorSpawner}, Task, }; @@ -284,7 +284,8 @@ impl TaskPool { let executor: &async_executor::Executor = &self.executor; let executor: &'env async_executor::Executor = unsafe { mem::transmute(executor) }; let thread_spawner = thread_executor.spawner(); - let thread_spawner: ThreadSpawner<'env> = unsafe { mem::transmute(thread_spawner) }; + let thread_spawner: ThreadExecutorSpawner<'env> = + unsafe { mem::transmute(thread_spawner) }; let spawned: ConcurrentQueue> = ConcurrentQueue::unbounded(); let spawned_ref: &'env ConcurrentQueue> = unsafe { mem::transmute(&spawned) }; @@ -401,7 +402,7 @@ impl Drop for TaskPool { #[derive(Debug)] pub struct Scope<'scope, 'env: 'scope, T> { executor: &'scope async_executor::Executor<'scope>, - thread_spawner: ThreadSpawner<'scope>, + thread_spawner: ThreadExecutorSpawner<'scope>, spawned: &'scope ConcurrentQueue>, // make `Scope` invariant over 'scope and 'env scope: PhantomData<&'scope mut &'scope ()>, diff --git a/crates/bevy_tasks/src/thread_executor.rs b/crates/bevy_tasks/src/thread_executor.rs index 2ab48bce6c1cd..4d9330a98042a 100644 --- a/crates/bevy_tasks/src/thread_executor.rs +++ b/crates/bevy_tasks/src/thread_executor.rs @@ -67,17 +67,17 @@ impl ThreadExecutor { /// Gets the `[ThreadSpawner]` for the thread executor. /// Use this to spawn tasks that run on the thread this was instantiated on. - pub fn spawner(&self) -> ThreadSpawner<'static> { - ThreadSpawner(self.executor.clone()) + pub fn spawner(&self) -> ThreadExecutorSpawner<'static> { + ThreadExecutorSpawner(self.executor.clone()) } /// Gets the `[ThreadTicker]` for this executor. /// Use this to tick the executor. /// It only returns the ticker if it's on the thread the executor was created on /// and returns `None` otherwise. - pub fn ticker(&self) -> Option { + pub fn ticker(&self) -> Option { if thread::current().id() == self.thread_id { - return Some(ThreadTicker { + return Some(ThreadExecutorTicker { executor: self.executor.clone(), _marker: PhantomData::default(), }); @@ -88,8 +88,8 @@ impl ThreadExecutor { /// Used to spawn on the [`ThreadExecutor`] #[derive(Debug, Clone)] -pub struct ThreadSpawner<'a>(Arc>); -impl<'a> ThreadSpawner<'a> { +pub struct ThreadExecutorSpawner<'a>(Arc>); +impl<'a> ThreadExecutorSpawner<'a> { /// Spawn a task on the thread executor pub fn spawn(&self, future: impl Future + Send + 'a) -> Task { self.0.spawn(future) @@ -100,12 +100,12 @@ impl<'a> ThreadSpawner<'a> { /// make progress unless it is manually ticked on the thread it was /// created on. #[derive(Debug)] -pub struct ThreadTicker { +pub struct ThreadExecutorTicker { executor: Arc>, // make type not send or sync _marker: PhantomData<*const ()>, } -impl ThreadTicker { +impl ThreadExecutorTicker { /// Tick the thread executor. pub fn tick(&self) -> impl Future + '_ { self.executor.tick()