Skip to content

Commit 9412f5c

Browse files
committed
samples: work-philosophers: Adjust for new futures version
Adjust for the new futures version, where there is a builder that then has a `start` that returns a `Work` that only holds on to the allocation, and waits for an answer. Signed-off-by: David Brown <david.brown@linaro.org>
1 parent f3ed624 commit 9412f5c

File tree

1 file changed

+11
-19
lines changed
  • samples/work-philosophers/src

1 file changed

+11
-19
lines changed

samples/work-philosophers/src/lib.rs

+11-19
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
extern crate alloc;
1212

13-
use zephyr::{printkln, sync::Arc, task::Wake, time::{Duration, NoWait}, work::futures::FutureWorkPoll};
13+
use zephyr::{printkln, time::Duration, work::futures::{sleep, WorkBuilder}};
1414

1515
/// How many philosophers. There will be the same number of forks.
1616
const _NUM_PHIL: usize = 6;
@@ -47,11 +47,7 @@ extern "C" fn rust_main() {
4747
// TODO: How to do as much on the stack as we can, for now, don't worry too much.
4848
// let mut th = pin!(th);
4949

50-
let mut th = FutureWorkPoll::new(th);
51-
let result = th.as_mut().submit(NoWait).unwrap();
52-
if !result.enqueued() {
53-
panic!("Problem submitting initial work: {:?}", result);
54-
}
50+
let th = WorkBuilder::new().start(th);
5551

5652
let result = th.sync_join();
5753
printkln!("th result: {:?}", result);
@@ -96,25 +92,21 @@ extern "C" fn rust_main() {
9692
*/
9793
}
9894

99-
/// Our local workqueue worker.
100-
struct PWaker;
101-
102-
impl Wake for PWaker {
103-
fn wake(this: Arc<Self>) {
104-
// Note that being able to call this 'self' would require the unstable
105-
// `abritrary_self_types` feature.
106-
let _ = this;
107-
todo!()
108-
}
109-
}
110-
11195
async fn phil_thread(n: usize) -> usize {
11296
printkln!("Child {} started", n);
113-
zephyr::work::futures::sleep(Duration::millis_at_least(1000)).await;
97+
show_it().await;
98+
sleep(Duration::millis_at_least(1000)).await;
11499
printkln!("Child {} done sleeping", n);
115100
42
116101
}
117102

103+
async fn show_it() {
104+
for i in 0..10 {
105+
sleep(Duration::millis_at_least(1)).await;
106+
printkln!("Tick: {i}");
107+
}
108+
}
109+
118110
/*
119111
fn phil_thread(n: usize, syncer: Arc<dyn ForkSync>, stats: Arc<Mutex<Stats>>) {
120112
printkln!("Child {} started: {:?}", n, syncer);

0 commit comments

Comments
 (0)