Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
fix: allow async task spawning in an async task
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin-Niederman committed Dec 12, 2023
1 parent 731533b commit 5dd3021
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion pros/src/async_runtime/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ impl Executor {
pub(crate) fn tick(&self) -> bool {
self.reactor.borrow_mut().tick();

match self.queue.borrow_mut().pop_front() {
let runnable = {
let mut queue = self.queue.borrow_mut();
queue.pop_front()
};
match runnable {
Some(runnable) => {
runnable.run();
true
Expand Down
8 changes: 6 additions & 2 deletions pros/src/task/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ impl<T: 'static> LocalKey<T> {
}

fn index(&'static self) -> &usize {
self.index.call_once(|| INDEX.fetch_add(1, core::sync::atomic::Ordering::Relaxed) as _)
self.index
.call_once(|| INDEX.fetch_add(1, core::sync::atomic::Ordering::Relaxed) as _)
}

pub fn set(&'static self, val: T) {
Expand All @@ -65,7 +66,10 @@ impl<T: 'static> LocalKey<T> {

let val = Box::leak(Box::new(val));

storage.borrow_mut().data.insert(index, NonNull::new((val as *mut T).cast()).unwrap());
storage
.borrow_mut()
.data
.insert(index, NonNull::new((val as *mut T).cast()).unwrap());
}

pub fn with<F, R>(&'static self, f: F) -> R
Expand Down
1 change: 0 additions & 1 deletion pros/src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::error::{bail_on, map_errno};

use snafu::Snafu;


/// Creates a task to be run 'asynchronously' (More information at the [FreeRTOS docs](https://www.freertos.org/taskandcr.html)).
/// Takes in a closure that can move variables if needed.
/// If your task has a loop it is advised to use [`sleep(duration)`](sleep) so that the task does not take up necessary system resources.
Expand Down

0 comments on commit 5dd3021

Please sign in to comment.