-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mpsc): initial sync and async channel APIs (#2)
Signed-off-by: Eliza Weisman <[email protected]>
- Loading branch information
Showing
17 changed files
with
1,486 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
macro_rules! test_println { | ||
($($arg:tt)*) => { | ||
if cfg!(test) { | ||
if crate::util::panic::panicking() { | ||
// getting the thread ID while panicking doesn't seem to play super nicely with loom's | ||
// mock lazy_static... | ||
println!("[PANIC {:>17}:{:<3}] {}", file!(), line!(), format_args!($($arg)*)) | ||
} else { | ||
println!("[{:?} {:>17}:{:<3}] {}", crate::loom::thread::current().id(), file!(), line!(), format_args!($($arg)*)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
macro_rules! test_dbg { | ||
($e:expr) => { | ||
match $e { | ||
e => { | ||
#[cfg(test)] | ||
test_println!("{} = {:?}", stringify!($e), &e); | ||
e | ||
} | ||
} | ||
}; | ||
} | ||
|
||
macro_rules! feature { | ||
( | ||
#![$meta:meta] | ||
$($item:item)* | ||
) => { | ||
$( | ||
#[cfg($meta)] | ||
#[cfg_attr(docsrs, doc(cfg($meta)))] | ||
$item | ||
)* | ||
} | ||
} | ||
|
||
#[allow(unused_macros)] | ||
macro_rules! unreachable_unchecked { | ||
($($arg:tt)+) => { | ||
crate::unreachable_unchecked!(@inner , format_args!(": {}", format_args!($($arg)*))) | ||
}; | ||
|
||
() => { | ||
crate::unreachable_unchecked!(@inner ".") | ||
}; | ||
|
||
(@inner $msg:expr) => { | ||
#[cfg(debug_assertions)] { | ||
panic!( | ||
"internal error: entered unreachable code{}\n\n\ | ||
/!\\ EXTREMELY SERIOUS WARNING /!\\\n | ||
This code should NEVER be entered; in release mode, this would \ | ||
have been an `unreachable_unchecked` hint. The fact that this \ | ||
occurred means something VERY bad is going on. \n\ | ||
Please contact the `thingbuf` maintainers immediately. Sorry!", | ||
$msg, | ||
); | ||
} | ||
#[cfg(not(debug_assertions))] | ||
unsafe { | ||
core::hint::unreachable_unchecked(); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//! Multi-producer, single-consumer channels using [`ThingBuf`](crate::ThingBuf). | ||
//! | ||
//! The default MPSC channel returned by the [`channel`] function is | ||
//! _asynchronous_: receiving from the channel is an `async fn`, and the | ||
//! receiving task willwait when there are no messages in the channel. | ||
//! | ||
//! If the "std" feature flag is enabled, this module also provides a | ||
//! synchronous channel, in the [`sync`] module. The synchronous receiver will | ||
//! instead wait for new messages by blocking the current thread. Naturally, | ||
//! this requires the Rust standard library. A synchronous channel | ||
//! can be constructed using the [`sync::channel`] function. | ||
mod async_impl; | ||
pub use self::async_impl::*; | ||
|
||
feature! { | ||
#![feature = "std"] | ||
pub mod sync; | ||
} | ||
|
||
#[derive(Debug)] | ||
#[non_exhaustive] | ||
pub enum TrySendError { | ||
AtCapacity(crate::AtCapacity), | ||
Closed(Closed), | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct Closed(pub(crate) ()); | ||
|
||
#[cfg(test)] | ||
mod tests; |
Oops, something went wrong.