Macro flexible_locks::mutex_new
[−]
[src]
macro_rules! mutex_new { ($m:expr, $d:expr) => { ... }; ($e:expr) => { ... }; }
Statically initializes a [Mutex
] or a [MutexWrap
].
This skips the [RawMutex::init
] method, so please be careful when using
this, and ensure the statically initialized raw mutex is properly usable.
For non-static initialization, it is recommended to use [Mutex::new
] or
[MutexWrap::new
].
Examples
#[macro_use] extern crate flexible_locks; #[macro_use] extern crate flexible_locks_derive; use flexible_locks::{Mutex, MutexWrap, RawMutex}; // Pick your choice of raw mutex; #[cfg(windows)] use flexible_locks::SRWLOCK as RawOsMutex; #[cfg(unix)] use flexible_locks::pthread_mutex_t as RawOsMutex; #[derive(MutexProtected)] struct Data { a: usize, b: usize, #[mutex] mutex: RawOsMutex, } static DATA: Mutex<Data> = mutex_new!(Data { a: 2, b: 1, #[cfg(windows)] mutex: srwlock_new!(), #[cfg(unix)] mutex: pthread_mutex_new!(), }); struct Data2 { a: usize, b: usize, } #[cfg(windows)] macro_rules! raw_os_mutex { () => { srwlock_new!() }; } #[cfg(unix)] macro_rules! raw_os_mutex { () => { pthread_mutex_new!() }; } static DATA2: MutexWrap<RawOsMutex, Data2> = mutex_new!( raw_os_mutex!(), Data2 { a: 2, b: 1 } );