diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-12-12 15:38:56 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-12 15:38:56 +0000 |
| commit | 640ca72c0e33b252026191ac9bc64fa6b0c9b166 (patch) | |
| tree | ea6be7b3f900a4dc44b1c1a4ac104e4154cd3ec5 /embassy-executor/src/arch/std.rs | |
| parent | 778bd76c1c2746ac9564132bcab0f8359feb7b13 (diff) | |
| parent | b1fe9c6955ff857e3729a0bb4727247e050fb7ae (diff) | |
Merge pull request #5047 from Gerharddc/executor-cancel
Add `run_until` function to std Executor as to support grafeul shutdown.
Diffstat (limited to 'embassy-executor/src/arch/std.rs')
| -rw-r--r-- | embassy-executor/src/arch/std.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/embassy-executor/src/arch/std.rs b/embassy-executor/src/arch/std.rs index c62ab723b..d4057144e 100644 --- a/embassy-executor/src/arch/std.rs +++ b/embassy-executor/src/arch/std.rs | |||
| @@ -55,11 +55,24 @@ mod thread { | |||
| 55 | /// | 55 | /// |
| 56 | /// This function never returns. | 56 | /// This function never returns. |
| 57 | pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! { | 57 | pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! { |
| 58 | self.run_until(init, || false); | ||
| 59 | unreachable!() | ||
| 60 | } | ||
| 61 | |||
| 62 | /// Run the executor until a flag is raised. | ||
| 63 | /// | ||
| 64 | /// This function is identical to `Executor::run()` apart from offering a `done` flag to stop execution. | ||
| 65 | pub fn run_until(&'static mut self, init: impl FnOnce(Spawner), mut done: impl FnMut() -> bool) { | ||
| 58 | init(self.inner.spawner()); | 66 | init(self.inner.spawner()); |
| 59 | 67 | ||
| 60 | loop { | 68 | loop { |
| 61 | unsafe { self.inner.poll() }; | 69 | unsafe { self.inner.poll() }; |
| 62 | self.signaler.wait() | 70 | |
| 71 | if done() { | ||
| 72 | break; | ||
| 73 | } | ||
| 74 | |||
| 75 | self.signaler.wait(); | ||
| 63 | } | 76 | } |
| 64 | } | 77 | } |
| 65 | } | 78 | } |
