diff options
Diffstat (limited to 'embassy-executor/src/raw')
| -rw-r--r-- | embassy-executor/src/raw/mod.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs index a7e65360d..bdaa32951 100644 --- a/embassy-executor/src/raw/mod.rs +++ b/embassy-executor/src/raw/mod.rs | |||
| @@ -41,7 +41,7 @@ use self::state::State; | |||
| 41 | use self::util::{SyncUnsafeCell, UninitCell}; | 41 | use self::util::{SyncUnsafeCell, UninitCell}; |
| 42 | pub use self::waker::task_from_waker; | 42 | pub use self::waker::task_from_waker; |
| 43 | use super::SpawnToken; | 43 | use super::SpawnToken; |
| 44 | use crate::Metadata; | 44 | use crate::{Metadata, SpawnError}; |
| 45 | 45 | ||
| 46 | #[no_mangle] | 46 | #[no_mangle] |
| 47 | extern "Rust" fn __embassy_time_queue_item_from_waker(waker: &Waker) -> &'static mut TimerQueueItem { | 47 | extern "Rust" fn __embassy_time_queue_item_from_waker(waker: &Waker) -> &'static mut TimerQueueItem { |
| @@ -220,11 +220,11 @@ impl<F: Future + 'static> TaskStorage<F> { | |||
| 220 | /// | 220 | /// |
| 221 | /// Once the task has finished running, you may spawn it again. It is allowed to spawn it | 221 | /// Once the task has finished running, you may spawn it again. It is allowed to spawn it |
| 222 | /// on a different executor. | 222 | /// on a different executor. |
| 223 | pub fn spawn(&'static self, future: impl FnOnce() -> F) -> SpawnToken<impl Sized> { | 223 | pub fn spawn(&'static self, future: impl FnOnce() -> F) -> Result<SpawnToken<impl Sized>, SpawnError> { |
| 224 | let task = AvailableTask::claim(self); | 224 | let task = AvailableTask::claim(self); |
| 225 | match task { | 225 | match task { |
| 226 | Some(task) => task.initialize(future), | 226 | Some(task) => Ok(task.initialize(future)), |
| 227 | None => SpawnToken::new_failed(), | 227 | None => Err(SpawnError::Busy), |
| 228 | } | 228 | } |
| 229 | } | 229 | } |
| 230 | 230 | ||
| @@ -353,10 +353,10 @@ impl<F: Future + 'static, const N: usize> TaskPool<F, N> { | |||
| 353 | } | 353 | } |
| 354 | } | 354 | } |
| 355 | 355 | ||
| 356 | fn spawn_impl<T>(&'static self, future: impl FnOnce() -> F) -> SpawnToken<T> { | 356 | fn spawn_impl<T>(&'static self, future: impl FnOnce() -> F) -> Result<SpawnToken<T>, SpawnError> { |
| 357 | match self.pool.iter().find_map(AvailableTask::claim) { | 357 | match self.pool.iter().find_map(AvailableTask::claim) { |
| 358 | Some(task) => task.initialize_impl::<T>(future), | 358 | Some(task) => Ok(task.initialize_impl::<T>(future)), |
| 359 | None => SpawnToken::new_failed(), | 359 | None => Err(SpawnError::Busy), |
| 360 | } | 360 | } |
| 361 | } | 361 | } |
| 362 | 362 | ||
| @@ -367,7 +367,7 @@ impl<F: Future + 'static, const N: usize> TaskPool<F, N> { | |||
| 367 | /// This will loop over the pool and spawn the task in the first storage that | 367 | /// This will loop over the pool and spawn the task in the first storage that |
| 368 | /// is currently free. If none is free, a "poisoned" SpawnToken is returned, | 368 | /// is currently free. If none is free, a "poisoned" SpawnToken is returned, |
| 369 | /// which will cause [`Spawner::spawn()`](super::Spawner::spawn) to return the error. | 369 | /// which will cause [`Spawner::spawn()`](super::Spawner::spawn) to return the error. |
| 370 | pub fn spawn(&'static self, future: impl FnOnce() -> F) -> SpawnToken<impl Sized> { | 370 | pub fn spawn(&'static self, future: impl FnOnce() -> F) -> Result<SpawnToken<impl Sized>, SpawnError> { |
| 371 | self.spawn_impl::<F>(future) | 371 | self.spawn_impl::<F>(future) |
| 372 | } | 372 | } |
| 373 | 373 | ||
| @@ -380,7 +380,7 @@ impl<F: Future + 'static, const N: usize> TaskPool<F, N> { | |||
| 380 | /// SAFETY: `future` must be a closure of the form `move || my_async_fn(args)`, where `my_async_fn` | 380 | /// SAFETY: `future` must be a closure of the form `move || my_async_fn(args)`, where `my_async_fn` |
| 381 | /// is an `async fn`, NOT a hand-written `Future`. | 381 | /// is an `async fn`, NOT a hand-written `Future`. |
| 382 | #[doc(hidden)] | 382 | #[doc(hidden)] |
| 383 | pub unsafe fn _spawn_async_fn<FutFn>(&'static self, future: FutFn) -> SpawnToken<impl Sized> | 383 | pub unsafe fn _spawn_async_fn<FutFn>(&'static self, future: FutFn) -> Result<SpawnToken<impl Sized>, SpawnError> |
| 384 | where | 384 | where |
| 385 | FutFn: FnOnce() -> F, | 385 | FutFn: FnOnce() -> F, |
| 386 | { | 386 | { |
