Struct abi_stable::external_types::parking_lot::mutex::RMutex [−][src]
#[repr(C)]pub struct RMutex<T> { /* fields omitted */ }
Expand description
A mutual exclusion lock that allows dynamic mutable borrows of shared data.
Poisoning
As opposed to the standard library version of this type, this mutex type does not use poisoning, simply unlocking the lock when a panic happens.
Example
use abi_stable::external_types::RMutex;
static MUTEX: RMutex<usize> = RMutex::new(0);
let guard = std::thread::spawn(|| {
for _ in 0..100 {
*MUTEX.lock() += 1;
}
});
for _ in 0..100 {
*MUTEX.lock() += 1;
}
guard.join().unwrap();
assert_eq!(*MUTEX.lock(), 200);
Implementations
Constructs a mutex,wrapping value
.
Example
use abi_stable::external_types::RMutex;
static MUTEX: RMutex<Option<String>> = RMutex::new(None);
let mutex = RMutex::new(0);
Unwraps this mutex into its wrapped data.
Example
use abi_stable::external_types::RMutex;
let mutex = RMutex::new("hello".to_string());
assert_eq!(mutex.into_inner().as_str(), "hello");
Gets a mutable reference to its wrapped data.
This does not require any locking,since it takes self
mutably.
Example
use abi_stable::external_types::RMutex;
let mut mutex = RMutex::new("Hello".to_string());
mutex.get_mut().push_str(", World!");
assert_eq!(mutex.lock().as_str(), "Hello, World!");
Acquires a mutex,blocking the current thread until it can.
This function returns a guard which releases the mutex when it is dropped.
Trying to lock the mutex in the same thread that holds the lock will cause a deadlock.
Example
use abi_stable::external_types::RMutex;
static MUTEX: RMutex<usize> = RMutex::new(0);
let guard = std::thread::spawn(|| *MUTEX.lock() += 1);
*MUTEX.lock() += 4;
guard.join().unwrap();
assert_eq!(*MUTEX.lock(), 5);
Attemps to acquire a mutex guard.
Returns the mutex guard if the mutex can be immediately acquired,
otherwise returns RNone
.
Example
use abi_stable::external_types::RMutex;
static MUTEX: RMutex<usize> = RMutex::new(0);
let mut guard = MUTEX.try_lock().unwrap();
assert!(MUTEX.try_lock().is_none());
assert_eq!(*guard, 0);
Attempts to acquire a mutex guard for the timeout
duration.
Once the timeout is reached,this will return RNone
,
otherwise it will return the mutex guard.
Example
use abi_stable::{external_types::RMutex, std_types::RDuration};
static MUTEX: RMutex<usize> = RMutex::new(0);
static DUR: RDuration = RDuration::from_millis(4);
let mut guard = MUTEX.try_lock_for(DUR).unwrap();
assert!(MUTEX.try_lock_for(DUR).is_none());
assert_eq!(*guard, 0);
Trait Implementations
type StaticEquivalent = _static_RMutex<__GetStaticEquivalent<T>>
type IsNonZeroType = False
type IsNonZeroType = False
Whether this type has a single invalid bit-pattern. Read more
The layout of the type provided by implementors.
const
-equivalents of the associated types.
Auto Trait Implementations
impl<T> !RefUnwindSafe for RMutex<T>
impl<T> UnwindSafe for RMutex<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
type ForSelf = WithMetadata_<T, T>
type ForSelf = WithMetadata_<T, T>
This is always WithMetadata_<Self, Self>
Compares the address of self
with the address of other
. Read more
Emulates the pipeline operator, allowing method syntax in more places. Read more
The same as piped
except that the function takes &Self
Useful for functions that take &Self
instead of Self
. Read more
The same as piped
, except that the function takes &mut Self
.
Useful for functions that take &mut Self
instead of Self
. Read more
Mutates self using a closure taking self by mutable reference, passing it along the method chain. Read more
Observes the value of self, passing it along unmodified. Useful in long method chains. Read more
Performs a conversion with Into
.
using the turbofish .into_::<_>()
syntax. Read more
Performs a reference to reference conversion with AsRef
,
using the turbofish .as_ref_::<_>()
syntax. Read more
Performs a mutable reference to mutable reference conversion with AsMut
,
using the turbofish .as_mut_::<_>()
syntax. Read more
unsafe fn transmute_element<T>(
self
) -> <Self as CanTransmuteElement<T>>::TransmutedPtr where
Self: CanTransmuteElement<T>,
unsafe fn transmute_element<T>(
self
) -> <Self as CanTransmuteElement<T>>::TransmutedPtr where
Self: CanTransmuteElement<T>,
Transmutes the element type of this pointer.. Read more
type Type = T
type Type = T
This is always Self
.
Converts a value back to the original type.
Converts a mutable reference back to the original type.
alloc
only.Converts a box back to the original type.
Converts a value back to the original type.
Converts a reference back to the original type.
Converts a mutable reference back to the original type.
alloc
only.Converts a box back to the original type.
alloc
only.Converts an Arc back to the original type.
alloc
only.Converts an Rc back to the original type.