Skip to content

Commit

Permalink
rename related structs to be more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
hymm committed Jan 9, 2023
1 parent aa678b3 commit 5d228cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
7 changes: 4 additions & 3 deletions crates/bevy_tasks/src/task_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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<FallibleTask<T>> = ConcurrentQueue::unbounded();
let spawned_ref: &'env ConcurrentQueue<FallibleTask<T>> =
unsafe { mem::transmute(&spawned) };
Expand Down Expand Up @@ -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<FallibleTask<T>>,
// make `Scope` invariant over 'scope and 'env
scope: PhantomData<&'scope mut &'scope ()>,
Expand Down
16 changes: 8 additions & 8 deletions crates/bevy_tasks/src/thread_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ThreadTicker> {
pub fn ticker(&self) -> Option<ThreadExecutorTicker> {
if thread::current().id() == self.thread_id {
return Some(ThreadTicker {
return Some(ThreadExecutorTicker {
executor: self.executor.clone(),
_marker: PhantomData::default(),
});
Expand All @@ -88,8 +88,8 @@ impl ThreadExecutor {

/// Used to spawn on the [`ThreadExecutor`]
#[derive(Debug, Clone)]
pub struct ThreadSpawner<'a>(Arc<Executor<'a>>);
impl<'a> ThreadSpawner<'a> {
pub struct ThreadExecutorSpawner<'a>(Arc<Executor<'a>>);
impl<'a> ThreadExecutorSpawner<'a> {
/// Spawn a task on the thread executor
pub fn spawn<T: Send + 'a>(&self, future: impl Future<Output = T> + Send + 'a) -> Task<T> {
self.0.spawn(future)
Expand All @@ -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<Executor<'static>>,
// make type not send or sync
_marker: PhantomData<*const ()>,
}
impl ThreadTicker {
impl ThreadExecutorTicker {
/// Tick the thread executor.
pub fn tick(&self) -> impl Future<Output = ()> + '_ {
self.executor.tick()
Expand Down

0 comments on commit 5d228cd

Please sign in to comment.