-
Notifications
You must be signed in to change notification settings - Fork 5
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Implement a barrier synchronization for async/await.
I implemented a barrier synchronization as follows.
awkernel/applications/measure_channel/src/lib.rs
Lines 30 to 63 in 7b7e050
| #[derive(Clone)] | |
| struct Barrier { | |
| count: Arc<AtomicUsize>, | |
| tx: Arc<Publisher<()>>, | |
| rx: Subscriber<()>, | |
| } | |
| impl Barrier { | |
| fn new(count: usize) -> Self { | |
| let attr = Attribute { | |
| queue_size: 1, | |
| ..Attribute::default() | |
| }; | |
| let (tx, rx) = pubsub::create_pubsub(attr); | |
| Self { | |
| count: Arc::new(AtomicUsize::new(count)), | |
| tx: Arc::new(tx), | |
| rx, | |
| } | |
| } | |
| async fn wait(&mut self) { | |
| if self | |
| .count | |
| .fetch_sub(1, core::sync::atomic::Ordering::Relaxed) | |
| == 1 | |
| { | |
| self.tx.send(()).await; | |
| } else { | |
| self.rx.recv().await; | |
| } | |
| } | |
| } |
However, the APIs are not compatible with other libraries like Tokio.
Metadata
Metadata
Labels
enhancementNew feature or requestNew feature or request