Skip to content

Commit cafb38d

Browse files
committed
CI
1 parent 5b79a0f commit cafb38d

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

crates/bevy_tasks/src/task_pool.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
use alloc::sync::Arc;
21
use core::{future::Future, marker::PhantomData, mem, panic::AssertUnwindSafe};
32
use std::thread::{self, JoinHandle};
43

54
use crate::executor::FallibleTask;
65
use concurrent_queue::ConcurrentQueue;
76
use futures_lite::FutureExt;
87

8+
#[cfg(feature = "portable-atomic")]
9+
use {alloc::boxed::Box, portable_atomic_util::Arc};
10+
11+
#[cfg(not(feature = "portable-atomic"))]
12+
use alloc::sync::Arc;
13+
914
use crate::{
1015
block_on,
1116
thread_executor::{ThreadExecutor, ThreadExecutorTicker},
@@ -70,7 +75,17 @@ impl TaskPoolBuilder {
7075
/// This is called on the thread itself and has access to all thread-local storage.
7176
/// This will block running async tasks on the thread until the callback completes.
7277
pub fn on_thread_spawn(mut self, f: impl Fn() + Send + Sync + 'static) -> Self {
73-
self.on_thread_spawn = Some(Arc::new(f));
78+
#[cfg(feature = "portable-atomic")]
79+
let arc = {
80+
let boxed = Box::new(f);
81+
let boxed: Box<dyn Fn() + Send + Sync + 'static> = boxed;
82+
Arc::from(boxed)
83+
};
84+
85+
#[cfg(not(feature = "portable-atomic"))]
86+
let arc = Arc::new(f);
87+
88+
self.on_thread_spawn = Some(arc);
7489
self
7590
}
7691

@@ -79,7 +94,17 @@ impl TaskPoolBuilder {
7994
/// This is called on the thread itself and has access to all thread-local storage.
8095
/// This will block thread termination until the callback completes.
8196
pub fn on_thread_destroy(mut self, f: impl Fn() + Send + Sync + 'static) -> Self {
82-
self.on_thread_destroy = Some(Arc::new(f));
97+
#[cfg(feature = "portable-atomic")]
98+
let arc = {
99+
let boxed = Box::new(f);
100+
let boxed: Box<dyn Fn() + Send + Sync + 'static> = boxed;
101+
Arc::from(boxed)
102+
};
103+
104+
#[cfg(not(feature = "portable-atomic"))]
105+
let arc = Arc::new(f);
106+
107+
self.on_thread_destroy = Some(arc);
83108
self
84109
}
85110

0 commit comments

Comments
 (0)