Skip to content

Commit 0bddf3d

Browse files
committed
Move throttle logic into executor
1 parent f0d7a31 commit 0bddf3d

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

examples/xbd-net/src/embassy/executor.rs

+4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ impl Executor {
3232
pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! {
3333
init(self.executor.spawner());
3434

35+
let throttle = 100;
36+
crate::println!("@@ Executor::run(): throttle: {} ms", throttle);
37+
3538
loop {
39+
crate::Xbd::msleep(throttle, false);
3640
unsafe { self.executor.poll() };
3741
}
3842
}

examples/xbd-net/src/embassy/mod.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
use super::xbd::{self, Xbd};
1+
use super::xbd;
22

33
mod executor;
44
use executor::Executor;
55

66
#[embassy_executor::task]
7-
async fn task_xbd_main(throttle: u32) {
7+
async fn task_xbd_main() {
88
super::xbd_main().await.unwrap();
9-
10-
//loop { Xbd::async_sleep(1000).await; } // yield -> executor busy
11-
//====
12-
//loop { Xbd::msleep(1000, true); } // not yield (debug for internal async API calls only) -> executor not busy
13-
//==== kludge
14-
loop { Xbd::async_sleep(1).await; Xbd::msleep(throttle, false); } // yield && less busy
159
}
1610

1711
#[embassy_executor::task]
@@ -47,11 +41,8 @@ impl Runtime {
4741
}
4842

4943
pub fn run(&'static mut self) -> ! {
50-
let throttle = 200;
51-
crate::println!("@@ task_xbd_main(): throttle: {} ms", throttle);
52-
5344
self.0.run(|spawner| {
54-
spawner.spawn(task_xbd_main(throttle)).unwrap();
45+
spawner.spawn(task_xbd_main()).unwrap();
5546
spawner.spawn(task_shell_stream()).unwrap();
5647
spawner.spawn(task_gcoap_server_stream()).unwrap();
5748
spawner.spawn(task_api_stream()).unwrap();

0 commit comments

Comments
 (0)