Struct spinlock::Spinlock
[−]
[src]
pub struct Spinlock<T> { /* fields omitted */ }
A wrapper for the data giving access in a thread-safe manner
Methods
impl<T> Spinlock<T>
[src]
fn new(user_data: T) -> Spinlock<T>
Creates a new spinlock wrapping the supplied data.
fn lock(&self) -> SpinlockGuard<T>
Locks the spinlock and returns a guard.
The returned value may be dereferenced for data access and the lock will be dropped when the guard falls out of scope.
let mylock = spinlock::Spinlock::new(0); { let mut data = mylock.lock(); // The lock is now locked and the data can be accessed *data += 1; } // The lock is dropped