Skip to content

Commit

Permalink
try to fix ci
Browse files Browse the repository at this point in the history
--still broken
  • Loading branch information
hymm committed Nov 6, 2022
1 parent b4edfab commit 0055a0e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
5 changes: 2 additions & 3 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ use bevy_ecs::{
SystemStage,
},
system::Resource,

world::World,
};
use bevy_tasks::ComputeTaskPool;
use bevy_tasks::{ComputeTaskPool, TaskPool};
use bevy_utils::{tracing::debug, HashMap, HashSet};
use std::fmt::Debug;

Expand Down Expand Up @@ -154,7 +153,7 @@ impl App {
pub fn update(&mut self) {
#[cfg(feature = "trace")]
let _bevy_frame_update_span = info_span!("frame").entered();
ComputeTaskPool::get().scope(|scope| {
ComputeTaskPool::init(TaskPool::default).scope(|scope| {
if self.run_once {
for sub_app in self.sub_apps.values_mut() {
(sub_app.extract)(&mut self.world, &mut sub_app.app);
Expand Down
18 changes: 16 additions & 2 deletions crates/bevy_tasks/src/main_thread_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ static MAIN_THREAD_EXECUTOR: OnceCell<MainThreadExecutor> = OnceCell::new();
/// Use to access the global main thread executor. Be aware that the main thread executor
/// only makes progress when it is ticked. This normally happens in `[TaskPool::scope]`.
#[derive(Debug)]
pub struct MainThreadExecutor(Arc<Executor<'static>>);
pub struct MainThreadExecutor(
// this is only pub crate for testing purposes, do not contruct otherwise
pub(crate) Arc<Executor<'static>>,
);

impl MainThreadExecutor {
/// Initializes the global `[MainThreadExecutor]` instance.
Expand Down Expand Up @@ -39,6 +42,17 @@ impl MainThreadExecutor {
/// Use this to tick the main thread executor.
/// Returns None if called on not the main thread.
pub fn ticker(&self) -> Option<MainThreadTicker> {
// always return ticker when testing to allow tests to run off main thread
dbg!("hjj");
#[cfg(test)]
if true {
dbg!("blah");
return Some(MainThreadTicker {
executor: self.0.clone(),
_marker: PhantomData::default(),
});
}

if let Some(is_main) = is_main_thread() {
if is_main {
return Some(MainThreadTicker {
Expand Down Expand Up @@ -69,7 +83,7 @@ pub struct MainThreadTicker {
impl MainThreadTicker {
/// Tick the main thread executor.
/// This needs to be called manually on the main thread if a `[TaskPool::scope]` is not active
pub fn tick<'a>(&'a self) -> impl Future<Output = ()> + 'a {
pub fn tick(&self) -> impl Future<Output = ()> + '_ {
self.executor.tick()
}
}
15 changes: 12 additions & 3 deletions crates/bevy_tasks/src/task_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,15 @@ impl TaskPool {
// transmute the lifetimes to 'env here to appease the compiler as it is unable to validate safety.
let executor: &async_executor::Executor = &self.executor;
let executor: &'env async_executor::Executor = unsafe { mem::transmute(executor) };
let main_thread_spawner = MainThreadExecutor::init().spawner();

#[cfg(not(test))]
let main_thread_executor = MainThreadExecutor::init();
// for testing configure a new instance of main thread executor for every scope
// this helps us pretend that the thread that an app or stage is constructed on is the main thread
#[cfg(test)]
let main_thread_executor = MainThreadExecutor(Arc::new(async_executor::Executor::new()));

let main_thread_spawner = main_thread_executor.spawner();
let main_thread_spawner: MainThreadSpawner<'env> =
unsafe { mem::transmute(main_thread_spawner) };
let spawned: ConcurrentQueue<async_executor::Task<T>> = ConcurrentQueue::unbounded();
Expand Down Expand Up @@ -277,9 +285,10 @@ impl TaskPool {
results
};

if let Some(main_thread_ticker) = MainThreadExecutor::get().ticker() {
if let Some(main_thread_ticker) = main_thread_executor.ticker() {
let tick_forever = async move {
loop {
dbg!("tivk");
main_thread_ticker.tick().await;
}
};
Expand Down Expand Up @@ -441,7 +450,7 @@ mod tests {
}

#[test]
fn test_mixed_spawn_on_scope_and_spawn() {
fn test_mixed_spawn_on_main_and_spawn() {
let pool = TaskPool::new();

let foo = Box::new(42);
Expand Down

0 comments on commit 0055a0e

Please sign in to comment.