Skip to content

Commit

Permalink
docs: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromfedricci committed Jul 27, 2024
1 parent 051ed7c commit 419317a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion examples/barging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use std::thread;

// Requires that the `barging` feature is enabled.
use mcslock::barging::spins::Mutex;
use mcslock::barging::spins::backoff::Mutex;

fn main() {
const N: usize = 10;
Expand Down
15 changes: 10 additions & 5 deletions src/barging/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@
//! [`lock`] and [`try_lock`]. Guards are also accessible as the closure argument
//! for [`lock_with`] and [`try_lock_with`] methods.
//!
//! The Mutex is generic over the relax strategy. User may choose a strategy
//! as long as it implements the [`Relax`] trait. There is a number of strategies
//! provided by the [`relax`] module. Each submodule provides type aliases for
//! [`Mutex`] and [`MutexGuard`] associated with one relax strategy. See their
//! documentation for more information.
//! This Mutex is generic over the two layers of relax strategies. User may
//! choose a strategy as long as it implements the [`Relax`] trait. The shared
//! lock relax strategy is associated with the `Rs` generic paramater. The
//! handoff relax strategy is then associated with the `Rq` generic parameter.
//! Backoff relax strategies are usually prefered for shared lock contention,
//! while non-backoff relax strategies are usually prefered for handoffs.
//!
//! There is a number of strategies provided by the [`relax`] module. Each
//! submodule provides type aliases for [`Mutex`] and [`MutexGuard`] associated
//! with one relax strategy. See their documentation for more information.
//!
//! [lock_api]: https://crates.io/crates/lock_api
//! [`lock`]: Mutex::lock
Expand Down
36 changes: 18 additions & 18 deletions src/barging/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ use crate::relax::Relax;
/// use std::sync::mpsc::channel;
///
/// use mcslock::barging::Mutex;
/// use mcslock::relax::Spin;
/// use mcslock::relax::{Spin, SpinBackoff};
///
/// type SpinMutex<T> = Mutex<T, Spin, Spin>;
/// type SpinMutex<T> = Mutex<T, SpinBackoff, Spin>;
///
/// const N: usize = 10;
///
Expand Down Expand Up @@ -79,9 +79,9 @@ impl<T, Rs, Rq> Mutex<T, Rs, Rq> {
///
/// ```
/// use mcslock::barging::Mutex;
/// use mcslock::relax::Spin;
/// use mcslock::relax::{Spin, SpinBackoff};
///
/// type SpinMutex<T> = Mutex<T, Spin, Spin>;
/// type SpinMutex<T> = Mutex<T, SpinBackoff, Spin>;
///
/// const MUTEX: SpinMutex<i32> = SpinMutex::new(0);
/// let mutex = SpinMutex::new(0);
Expand Down Expand Up @@ -111,9 +111,9 @@ impl<T, Rs, Rq> Mutex<T, Rs, Rq> {
///
/// ```
/// use mcslock::barging::Mutex;
/// use mcslock::relax::Spin;
/// use mcslock::relax::{Spin, SpinBackoff};
///
/// type SpinMutex<T> = Mutex<T, Spin, Spin>;
/// type SpinMutex<T> = Mutex<T, SpinBackoff, Spin>;
///
/// let mutex = SpinMutex::new(0);
/// assert_eq!(mutex.into_inner(), 0);
Expand Down Expand Up @@ -141,9 +141,9 @@ impl<T: ?Sized, Rs: Relax, Rq: Relax> Mutex<T, Rs, Rq> {
/// use std::thread;
///
/// use mcslock::barging::Mutex;
/// use mcslock::relax::Spin;
/// use mcslock::relax::{Spin, SpinBackoff};
///
/// type SpinMutex<T> = Mutex<T, Spin, Spin>;
/// type SpinMutex<T> = Mutex<T, SpinBackoff, Spin>;
///
/// let mutex = Arc::new(SpinMutex::new(0));
/// let c_mutex = Arc::clone(&mutex);
Expand Down Expand Up @@ -188,9 +188,9 @@ impl<T: ?Sized, Rs: Relax, Rq: Relax> Mutex<T, Rs, Rq> {
/// use std::thread;
///
/// use mcslock::barging::Mutex;
/// use mcslock::relax::Spin;
/// use mcslock::relax::{Spin, SpinBackoff};
///
/// type SpinMutex<T> = Mutex<T, Spin, Spin>;
/// type SpinMutex<T> = Mutex::<T, SpinBackoff, Spin>;
///
/// let mutex = Arc::new(SpinMutex::new(0));
/// let c_mutex = Arc::clone(&mutex);
Expand Down Expand Up @@ -237,9 +237,9 @@ impl<T: ?Sized, Rs, Rq> Mutex<T, Rs, Rq> {
/// use std::thread;
///
/// use mcslock::barging::Mutex;
/// use mcslock::relax::Spin;
/// use mcslock::relax::{Spin, SpinBackoff};
///
/// type SpinMutex<T> = Mutex<T, Spin, Spin>;
/// type SpinMutex<T> = Mutex::<T, SpinBackoff, Spin>;
///
/// let mutex = Arc::new(SpinMutex::new(0));
/// let c_mutex = Arc::clone(&mutex);
Expand Down Expand Up @@ -280,9 +280,9 @@ impl<T: ?Sized, Rs, Rq> Mutex<T, Rs, Rq> {
/// use std::thread;
///
/// use mcslock::barging::Mutex;
/// use mcslock::relax::Spin;
/// use mcslock::relax::{Spin, SpinBackoff};
///
/// type SpinMutex<T> = Mutex<T, Spin, Spin>;
/// type SpinMutex<T> = Mutex::<T, SpinBackoff, Spin>;
///
/// let mutex = Arc::new(SpinMutex::new(0));
/// let c_mutex = Arc::clone(&mutex);
Expand Down Expand Up @@ -327,9 +327,9 @@ impl<T: ?Sized, Rs, Rq> Mutex<T, Rs, Rq> {
///
/// ```
/// use mcslock::barging::Mutex;
/// use mcslock::relax::Spin;
/// use mcslock::relax::{Spin, SpinBackoff};
///
/// type SpinMutex<T> = Mutex<T, Spin, Spin>;
/// type SpinMutex<T> = Mutex<T, SpinBackoff, Spin>;
///
/// let mutex = SpinMutex::new(0);
/// let guard = mutex.lock();
Expand All @@ -352,9 +352,9 @@ impl<T: ?Sized, Rs, Rq> Mutex<T, Rs, Rq> {
///
/// ```
/// use mcslock::barging::Mutex;
/// use mcslock::relax::Spin;
/// use mcslock::relax::{Spin, SpinBackoff};
///
/// type SpinMutex<T> = Mutex<T, Spin, Spin>;
/// type SpinMutex<T> = Mutex<T, SpinBackoff, Spin>;
///
/// let mut mutex = SpinMutex::new(0);
/// *mutex.get_mut() = 10;
Expand Down

0 comments on commit 419317a

Please sign in to comment.