Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Mea (Make Easy Async) is a runtime-agnostic library providing essential synchron
* [**Semaphore**](https://docs.rs/mea/*/mea/semaphore/struct.Semaphore.html): A synchronization primitive that controls access to a shared resource.
* [**ShutdownSend & ShutdownRecv**](https://docs.rs/mea/*/mea/shutdown/): A composite synchronization primitive for managing shutdown signals.
* [**WaitGroup**](https://docs.rs/mea/*/mea/waitgroup/struct.WaitGroup.html): A synchronization primitive that allows waiting for multiple tasks to complete.
* [**oneshot::channel**](https://docs.rs/mea/*/mea/oneshot/index.html): A one-shot channel for sending a single value between tasks.

## Installation

Expand Down Expand Up @@ -68,6 +69,7 @@ This crate collects runtime-agnostic synchronization primitives from spare parts
* **RwLock** is derived from `tokio::sync::RwLock`, but the `max_readers` can be any `usize` instead of `[0, u32::MAX >> 3]`. No blocking method is provided, since it can be easily implemented with block_on of any runtime.
* **Semaphore** is derived from `tokio::sync::Semaphore`, without `close` method since it is quite tricky to use. And thus, this semaphore doesn't have the limitation of max permits. Besides, new methods like `forget_exact` are added to fit the specific use case.
* **WaitGroup** is inspired by [`waitgroup-rs`](https://github.com/laizy/waitgroup-rs), with a different implementation based on the internal `CountdownState` primitive. It fixes the unsound issue as described [here](https://github.com/rust-lang/futures-rs/issues/2880#issuecomment-2333842804).
* **oneshot::channel** is derived from [`oneshot`](https://github.com/faern/oneshot), with significant simplifications since we need not support synchronized receiving functions.

Other parts are written from scratch.

Expand Down
17 changes: 17 additions & 0 deletions mea/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
//! * [`ShutdownSend`] & [`ShutdownRecv`]: A composite synchronization primitive for managing
//! shutdown signals
//! * [`WaitGroup`]: A synchronization primitive that allows waiting for multiple tasks to complete
//! * [`oneshot`]: A one-shot channel for sending a single value between tasks.
//!
//! ## Runtime Agnostic
//!
Expand Down Expand Up @@ -62,6 +63,7 @@ pub mod barrier;
pub mod condvar;
pub mod latch;
pub mod mutex;
pub mod oneshot;
pub mod rwlock;
pub mod semaphore;
pub mod shutdown;
Expand All @@ -83,12 +85,14 @@ mod tests {
use crate::latch::Latch;
use crate::mutex::Mutex;
use crate::mutex::MutexGuard;
use crate::oneshot;
use crate::rwlock::RwLock;
use crate::rwlock::RwLockReadGuard;
use crate::rwlock::RwLockWriteGuard;
use crate::semaphore::Semaphore;
use crate::shutdown::ShutdownRecv;
use crate::shutdown::ShutdownSend;
use crate::waitgroup::Wait;
use crate::waitgroup::WaitGroup;

#[test]
Expand All @@ -106,6 +110,15 @@ mod tests {
do_assert_send_and_sync::<RwLock<i64>>();
do_assert_send_and_sync::<RwLockReadGuard<'_, i64>>();
do_assert_send_and_sync::<RwLockWriteGuard<'_, i64>>();
do_assert_send_and_sync::<oneshot::Sender<i64>>();
do_assert_send_and_sync::<oneshot::SendError<i64>>();
}

#[test]
fn assert_send() {
fn do_assert_send<T: Send>() {}
do_assert_send::<oneshot::Receiver<i64>>();
do_assert_send::<oneshot::Recv<i64>>();
}

#[test]
Expand All @@ -118,10 +131,14 @@ mod tests {
do_assert_unpin::<ShutdownSend>();
do_assert_unpin::<ShutdownRecv>();
do_assert_unpin::<WaitGroup>();
do_assert_unpin::<Wait>();
do_assert_unpin::<Mutex<i64>>();
do_assert_unpin::<MutexGuard<'_, i64>>();
do_assert_unpin::<RwLock<i64>>();
do_assert_unpin::<RwLockReadGuard<'_, i64>>();
do_assert_unpin::<RwLockWriteGuard<'_, i64>>();
do_assert_unpin::<oneshot::Sender<i64>>();
do_assert_unpin::<oneshot::Receiver<i64>>();
do_assert_unpin::<oneshot::Recv<i64>>();
}
}
Loading