Flexible Locks
This crate aims at providing generic, flexible implementations of locking
primitives. For now, it only provides Mutex
types (i.e. no RwLock
, etc.),
without poisoning, and without try_lock
. Support for those can be
added in the future if there is interest (patches welcome). Poisoning is not
necessary with panic=abort.
The provided types allow flexibility in layout and locking implementation.
Differences from std::sync::Mutex
- No poisoning.
- No
try_lock
. - The underlying raw mutex primitive can be of any kind, within a
Box
or not, as long as theRawMutex
trait is implemented. Choose carefully. - The raw mutex primitive can be embedded anywhere in the data type. See the
MutexWrap
type for a variant that looks more likestd::sync::Mutex
, but still allows to use a specific raw mutex primitive. - With care, this can allow to share data through FFI and contend on the same
locks. See the
ffi-example
directory.
Examples
extern crate flexible_locks;
extern crate flexible_locks_derive;
use ;
// Pick your choice of raw mutex;
use SRWLOCK as RawOsMutex;
use pthread_mutex_t as RawOsMutex;
use Arc;
use thread;
use channel;
const N: usize = 10;
Features
The parking_lot
feature can be enabled, providing a RawMutex
implementation for parking_log::Mutex<()>
.
License: Apache-2.0/MIT