aboutsummaryrefslogtreecommitdiff
path: root/src/export/executor.rs
diff options
context:
space:
mode:
authorGravatar Emil Fresk <emil.fresk@gmail.com> 2023-01-09 21:02:53 +0100
committerGravatar Henrik Tjäder <henrik@tjaders.com> 2023-03-01 00:33:29 +0100
commitcd790a94286cdc307d399b7f7a43e305e90de5bf (patch)
tree5a83dd0739c90fb848744c22bcbe689eed1f1fcf /src/export/executor.rs
parent1eabb94f0424d7ff85786ad05615da69a379f01d (diff)
downloadrtic-cd790a94286cdc307d399b7f7a43e305e90de5bf.tar.gz
rtic-cd790a94286cdc307d399b7f7a43e305e90de5bf.tar.zst
rtic-cd790a94286cdc307d399b7f7a43e305e90de5bf.zip
More work on new spawn/executor
Diffstat (limited to 'src/export/executor.rs')
-rw-r--r--src/export/executor.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/export/executor.rs b/src/export/executor.rs
index 874ee192..2f88eff9 100644
--- a/src/export/executor.rs
+++ b/src/export/executor.rs
@@ -1,9 +1,9 @@
+use super::atomic::{AtomicBool, Ordering};
use core::{
cell::UnsafeCell,
future::Future,
mem::{self, MaybeUninit},
pin::Pin,
- sync::atomic::{AtomicBool, Ordering},
task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
};
@@ -53,9 +53,11 @@ impl<F: Future> AsyncTaskExecutor<F> {
self.running.load(Ordering::Relaxed)
}
- /// Checks if a waker has pended the executor.
- pub fn is_pending(&self) -> bool {
- self.pending.load(Ordering::Relaxed)
+ /// Checks if a waker has pended the executor and simultaneously clears the flag.
+ pub fn check_and_clear_pending(&self) -> bool {
+ self.pending
+ .compare_exchange(true, false, Ordering::Relaxed, Ordering::Relaxed)
+ .is_ok()
}
// Used by wakers to indicate that the executor needs to run.
@@ -80,6 +82,7 @@ impl<F: Future> AsyncTaskExecutor<F> {
debug_assert!(self.running.load(Ordering::Relaxed));
self.task.get().write(MaybeUninit::new(future));
+ self.set_pending();
}
/// Poll the future in the executor.