Expand description
§Overview
hermit-sync provides synchronization primitives targeted at operating system kernels.
§Interrupts
without_interrupts runs a closure with disabled interrupts.
§Mutexes
This crate provides three kinds of mutexes based on lock_api::RawMutex:
- RawSpinMutexis a simple test and test-and-set spinlock with exponential backoff.
- RawTicketMutexis a fair ticket lock with exponential backoff.
- RawInterruptMutexwraps another mutex and disables interrupts while locked.
For API documentation see lock_api::Mutex.
§Examples
use hermit_sync::InterruptSpinMutex;
static NUMBER: InterruptSpinMutex<usize> = InterruptSpinMutex::new(0);
// Modify the data
*NUMBER.lock() = 2;
// Read the data
let answer = *NUMBER.lock();
assert_eq!(2, answer);§Initializing Static Data
There are two primitives for safely initializing static data based on generic_once_cell and RawSpinMutex:
- OnceCellcan be written to only once and can then be accessed without locking.
- Lazywraps a- OnceCelland is initialized on the first access from a closure.
For API documentation see generic_once_cell::OnceCell and generic_once_cell::Lazy.
§Examples
use std::collections::HashMap;
use hermit_sync::InterruptLazy;
static MAP: InterruptLazy<HashMap<usize, String>> = InterruptLazy::new(|| {
    // This is run on the first access of MAP.
    let mut map = HashMap::new();
    map.insert(42, "Ferris".to_string());
    map.insert(3, "やれやれだぜ".to_string());
    map
});
assert_eq!("Ferris", MAP.get(&42).unwrap());§Accessing Static Data Mutably
There is ExclusiveCell for safely accessing static data mutable once.
§Type Definitions
This crate provides a lot of type definitions for ease of use:
Structs§
- CallOnce 
- A synchronization primitive that can only be called once sucessfully.
- CallOnce Error 
- The CallOnceErrorerror indicates thatCallOnce::call_oncehas been called more than once.
- ExclusiveCell 
- A synchronization primitive which can be accessed only once.
- RawInterruptMutex 
- A mutex for sharing data with interrupt handlers or signal handlers.
- RawOneShot Mutex 
- A one-shot mutex that panics instead of (dead)locking on contention.
- RawOneShot RwLock 
- A one-shot readers-writer lock that panics instead of (dead)locking on contention.
- RawTicketMutex 
- A fair ticket lock with exponential backoff.
Functions§
- without_interrupts 
- Run a closure with disabled interrupts.
Type Aliases§
- InterruptLazy 
- A generic_once_cell::Lazy, initialized usingRawInterruptSpinMutex.
- InterruptMutex 
- A lock_api::Mutexbased onRawInterruptMutex.
- InterruptMutex Guard 
- A lock_api::MutexGuardbased onRawInterruptMutex.
- InterruptOnce Cell 
- A generic_once_cell::OnceCell, initialized usingRawInterruptSpinMutex.
- InterruptOneShot Mutex 
- A lock_api::Mutexbased onRawInterruptOneShotMutex.
- InterruptOneShot Mutex Guard 
- A lock_api::MutexGuardbased onRawInterruptOneShotMutex.
- InterruptSpin Mutex 
- A lock_api::Mutexbased onRawInterruptSpinMutex.
- InterruptSpin Mutex Guard 
- A lock_api::MutexGuardbased onRawInterruptSpinMutex.
- InterruptTicket Mutex 
- A lock_api::Mutexbased onRawInterruptTicketMutex.
- InterruptTicket Mutex Guard 
- A lock_api::MutexGuardbased onRawInterruptTicketMutex.
- Lazy
- A generic_once_cell::Lazy, initialized usingRawSpinMutex.
- OnceCell 
- A generic_once_cell::OnceCell, initialized usingRawSpinMutex.
- OneShotMutex 
- A lock_api::Mutexbased onRawOneShotMutex.
- OneShotMutex Guard 
- A lock_api::MutexGuardbased onRawOneShotMutex.
- OneShotRwLock 
- A lock_api::RwLockbased onRawOneShotRwLock.
- OneShotRwLock Read Guard 
- A lock_api::RwLockReadGuardbased onRawOneShotRwLock.
- OneShotRwLock Upgradable Read Guard 
- A lock_api::RwLockUpgradableReadGuardbased onRawOneShotRwLock.
- OneShotRwLock Write Guard 
- A lock_api::RwLockWriteGuardbased onRawOneShotRwLock.
- RawInterruptOneShot Mutex 
- An interrupt-safe RawOneShotMutex.
- RawInterruptSpin Mutex 
- An interrupt-safe RawSpinMutex.
- RawInterruptTicket Mutex 
- An interrupt-safe RawTicketMutex.
- RawRwSpin Lock 
- A simple spinning, read-preferring readers-writer lock with exponential backoff.
- RawSpinMutex 
- A simple spinlock with exponential backoff.
- RwSpinLock 
- A lock_api::RwLockbased onRawRwSpinLock.
- RwSpinLock Read Guard 
- A lock_api::RwLockReadGuardbased onRawRwSpinLock.
- RwSpinLock Upgradable Read Guard 
- A lock_api::RwLockUpgradableReadGuardbased onRawRwSpinLock.
- RwSpinLock Write Guard 
- A lock_api::RwLockWriteGuardbased onRawRwSpinLock.
- SpinMutex 
- A lock_api::Mutexbased onRawSpinMutex.
- SpinMutex Guard 
- A lock_api::MutexGuardbased onRawSpinMutex.
- TicketMutex 
- A lock_api::Mutexbased onRawTicketMutex.
- TicketMutex Guard 
- A lock_api::MutexGuardbased onRawTicketMutex.