Skip to content

Commit

Permalink
Move throttle logic into executor
Browse files Browse the repository at this point in the history
  • Loading branch information
j-devel committed May 17, 2024
1 parent f0d7a31 commit 0bddf3d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
4 changes: 4 additions & 0 deletions examples/xbd-net/src/embassy/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ impl Executor {
pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! {
init(self.executor.spawner());

let throttle = 100;
crate::println!("@@ Executor::run(): throttle: {} ms", throttle);

loop {
crate::Xbd::msleep(throttle, false);
unsafe { self.executor.poll() };
}
}
Expand Down
15 changes: 3 additions & 12 deletions examples/xbd-net/src/embassy/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
use super::xbd::{self, Xbd};
use super::xbd;

mod executor;
use executor::Executor;

#[embassy_executor::task]
async fn task_xbd_main(throttle: u32) {
async fn task_xbd_main() {
super::xbd_main().await.unwrap();

//loop { Xbd::async_sleep(1000).await; } // yield -> executor busy
//====
//loop { Xbd::msleep(1000, true); } // not yield (debug for internal async API calls only) -> executor not busy
//==== kludge
loop { Xbd::async_sleep(1).await; Xbd::msleep(throttle, false); } // yield && less busy
}

#[embassy_executor::task]
Expand Down Expand Up @@ -47,11 +41,8 @@ impl Runtime {
}

pub fn run(&'static mut self) -> ! {
let throttle = 200;
crate::println!("@@ task_xbd_main(): throttle: {} ms", throttle);

self.0.run(|spawner| {
spawner.spawn(task_xbd_main(throttle)).unwrap();
spawner.spawn(task_xbd_main()).unwrap();
spawner.spawn(task_shell_stream()).unwrap();
spawner.spawn(task_gcoap_server_stream()).unwrap();
spawner.spawn(task_api_stream()).unwrap();
Expand Down

0 comments on commit 0bddf3d

Please sign in to comment.