Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: polish docs and tests #20

Merged
merged 1 commit into from
Dec 18, 2024
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
38 changes: 26 additions & 12 deletions mea/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,32 @@ mod tests {
use crate::waitgroup::WaitGroup;

#[test]
fn send_and_sync() {
fn assert_send_and_sync<T: Send + Sync>() {}
assert_send_and_sync::<Barrier>();
assert_send_and_sync::<Condvar>();
assert_send_and_sync::<Latch>();
assert_send_and_sync::<Semaphore>();
assert_send_and_sync::<WaitGroup>();
fn assert_send_and_sync() {
fn do_assert_send_and_sync<T: Send + Sync>() {}
do_assert_send_and_sync::<Barrier>();
do_assert_send_and_sync::<Condvar>();
do_assert_send_and_sync::<Latch>();
do_assert_send_and_sync::<Semaphore>();
do_assert_send_and_sync::<WaitGroup>();
do_assert_send_and_sync::<Mutex<i64>>();
do_assert_send_and_sync::<MutexGuard<'_, i64>>();
do_assert_send_and_sync::<RwLock<i64>>();
do_assert_send_and_sync::<RwLockReadGuard<'_, i64>>();
do_assert_send_and_sync::<RwLockWriteGuard<'_, i64>>();
}

assert_send_and_sync::<Mutex<i64>>();
assert_send_and_sync::<MutexGuard<'_, i64>>();
assert_send_and_sync::<RwLock<i64>>();
assert_send_and_sync::<RwLockReadGuard<'_, i64>>();
assert_send_and_sync::<RwLockWriteGuard<'_, i64>>();
#[test]
fn assert_unpin() {
fn do_assert_unpin<T: Unpin>() {}
do_assert_unpin::<Barrier>();
do_assert_unpin::<Condvar>();
do_assert_unpin::<Latch>();
do_assert_unpin::<Semaphore>();
do_assert_unpin::<WaitGroup>();
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>>();
}
}
16 changes: 10 additions & 6 deletions mea/src/mutex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,17 @@ impl<T> Mutex<T> {
}

impl<T: ?Sized> Mutex<T> {
/// Locks this mutex, causing the current task to yield until the lock has
/// been acquired. When the lock has been acquired, function returns a
/// [`MutexGuard`].
/// Locks this mutex, causing the current task to yield until the lock has been acquired. When
/// the lock has been acquired, function returns a [`MutexGuard`].
///
/// This method is async and will yield the current task if the mutex is
/// currently held by another task. When the mutex becomes available, the
/// task will be woken up and given the lock.
/// This method is async and will yield the current task if the mutex is currently held by
/// another task. When the mutex becomes available, the task will be woken up and given the
/// lock.
///
/// # Cancel safety
///
/// This method uses a queue to fairly distribute locks in the order they were requested.
/// Cancelling a call to `lock` makes you lose your place in the queue.
///
/// # Examples
///
Expand Down
10 changes: 7 additions & 3 deletions mea/src/semaphore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,13 @@ impl Semaphore {

/// Acquires `n` permits from the semaphore.
///
/// If the permits are not immediately available, this method will wait until
/// they become available. Returns a [`SemaphorePermit`] that will release the
/// permits when dropped.
/// If the permits are not immediately available, this method will wait until they become
/// available. Returns a [`SemaphorePermit`] that will release the permits when dropped.
///
/// # Cancel safety
///
/// This method uses a queue to fairly distribute permits in the order they were requested.
/// Cancelling a call to `acquire` makes you lose your place in the queue.
///
/// # Examples
///
Expand Down