diff options
author | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
---|---|---|
committer | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
commit | 1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch) | |
tree | 7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/flume/src/signal.rs | |
parent | 5ecd8cf2cba827454317368b68571df0d13d7842 (diff) | |
download | fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip |
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/flume/src/signal.rs')
-rw-r--r-- | vendor/flume/src/signal.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/vendor/flume/src/signal.rs b/vendor/flume/src/signal.rs new file mode 100644 index 0000000..89395a3 --- /dev/null +++ b/vendor/flume/src/signal.rs @@ -0,0 +1,33 @@ +use std::{thread::{self, Thread}, time::Duration, any::Any}; + +pub trait Signal: Send + Sync + 'static { + /// Fire the signal, returning whether it is a stream signal. This is because streams do not + /// acquire a message when woken, so signals must be fired until one that does acquire a message + /// is fired, otherwise a wakeup could be missed, leading to a lost message until one is eagerly + /// grabbed by a receiver. + fn fire(&self) -> bool; + fn as_any(&self) -> &(dyn Any + 'static); + fn as_ptr(&self) -> *const (); +} + +pub struct SyncSignal(Thread); + +impl Default for SyncSignal { + fn default() -> Self { + Self(thread::current()) + } +} + +impl Signal for SyncSignal { + fn fire(&self) -> bool { + self.0.unpark(); + false + } + fn as_any(&self) -> &(dyn Any + 'static) { self } + fn as_ptr(&self) -> *const () { self as *const _ as *const () } +} + +impl SyncSignal { + pub fn wait(&self) { thread::park(); } + pub fn wait_timeout(&self, dur: Duration) { thread::park_timeout(dur); } +} |