Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from pbzweihander/default-mutex
Browse files Browse the repository at this point in the history
Derive Default trait for mutexes
  • Loading branch information
MabezDev authored Jun 28, 2021
2 parents f638f49 + a4ac228 commit b9bac84
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub extern crate mutex_trait;
pub use mutex_trait::Mutex;

/// A spinlock and critical section section based mutex.
#[derive(Default)]
pub struct CriticalSectionSpinLockMutex<T> {
data: spin::Mutex<T>,
}
Expand Down Expand Up @@ -39,6 +40,7 @@ unsafe impl<T> Sync for CriticalSectionSpinLockMutex<T> where T: Send {}
/// **This Mutex is only safe on single-core applications.**
///
/// A `CriticalSection` **is not sufficient** to ensure exclusive access across cores.
#[derive(Default)]
pub struct CriticalSectionMutex<T> {
data: UnsafeCell<T>,
}
Expand Down Expand Up @@ -66,6 +68,7 @@ impl<T> mutex_trait::Mutex for &'_ CriticalSectionMutex<T> {
unsafe impl<T> Sync for CriticalSectionMutex<T> where T: Send {}

/// A spinlock based mutex.
#[derive(Default)]
pub struct SpinLockMutex<T> {
data: spin::Mutex<T>,
}
Expand Down

0 comments on commit b9bac84

Please sign in to comment.