1
0
forked from ROMEO/nexosim

Replace event module by async-event crate

This commit is contained in:
Serge Barral
2023-07-16 16:37:40 +02:00
parent 0bcecbfdc2
commit 3fcb05eae9
3 changed files with 6 additions and 1081 deletions

View File

@ -25,6 +25,7 @@ dev-hooks = []
dev-logs = [] dev-logs = []
[dependencies] [dependencies]
async-event = "0.1"
crossbeam-utils = "0.8" crossbeam-utils = "0.8"
diatomic-waker = "0.1" diatomic-waker = "0.1"
futures-task = "0.3" futures-task = "0.3"

View File

@ -2,7 +2,6 @@
//! simulation models. //! simulation models.
#![warn(missing_docs, missing_debug_implementations, unreachable_pub)] #![warn(missing_docs, missing_debug_implementations, unreachable_pub)]
mod event;
mod queue; mod queue;
use std::error; use std::error;
@ -13,10 +12,10 @@ use std::num::NonZeroUsize;
use std::sync::atomic::{self, AtomicUsize, Ordering}; use std::sync::atomic::{self, AtomicUsize, Ordering};
use std::sync::Arc; use std::sync::Arc;
use async_event::Event;
use diatomic_waker::primitives::DiatomicWaker; use diatomic_waker::primitives::DiatomicWaker;
use recycle_box::RecycleBox; use recycle_box::RecycleBox;
use event::Event;
use queue::{PopError, PushError, Queue}; use queue::{PopError, PushError, Queue};
use recycle_box::coerce_box; use recycle_box::coerce_box;
@ -113,7 +112,7 @@ impl<M: Model> Receiver<M> {
// Now that `msg` was consumed and its slot in the queue was // Now that `msg` was consumed and its slot in the queue was
// freed, signal to one awaiting sender that one slot is // freed, signal to one awaiting sender that one slot is
// available for sending. // available for sending.
self.inner.sender_signal.notify(1); self.inner.sender_signal.notify_one();
// Await the future provided by the message. // Await the future provided by the message.
let mut fut = RecycleBox::into_pin(fut); let mut fut = RecycleBox::into_pin(fut);
@ -145,7 +144,7 @@ impl<M: Model> Receiver<M> {
self.inner.queue.close(); self.inner.queue.close();
// Notify all blocked senders that the channel is closed. // Notify all blocked senders that the channel is closed.
self.inner.sender_signal.notify(usize::MAX); self.inner.sender_signal.notify_all();
} }
} }
@ -164,7 +163,7 @@ impl<M> Drop for Receiver<M> {
self.inner.queue.close(); self.inner.queue.close();
// Notify all blocked senders that the channel is closed. // Notify all blocked senders that the channel is closed.
self.inner.sender_signal.notify(usize::MAX); self.inner.sender_signal.notify_all();
} }
} }
@ -239,7 +238,7 @@ impl<M: Model> Sender<M> {
// Notify the receiver and all blocked senders that the channel is // Notify the receiver and all blocked senders that the channel is
// closed. // closed.
self.inner.receiver_signal.notify(); self.inner.receiver_signal.notify();
self.inner.sender_signal.notify(usize::MAX); self.inner.sender_signal.notify_all();
} }
/// Checks if the channel is closed. /// Checks if the channel is closed.

File diff suppressed because it is too large Load Diff