Module namedlock::ownedmutexguard
[−]
[src]
Mutex guards that own the Mutex.
A standard MutexGuard
requires the Mutex to live at least as long as the
guard. This module contains a new guard type OwnedMutexGuard
, which
guarantees that an OwnedMutex
stays alive until the guard is released,
without any restrictions on the lifetime of the mutex.
Arc<Mutex<_>>
, Rc<Mutex<_>>
and Box<Mutex<_>>
implement OwnedMutex
.
The OwnedMutex.owned_lock
function is used to create a new OwnedMutexGuard.
use std::sync::{Mutex,Arc}; use namedlock::lockresult::LockResult; use namedlock::ownedmutexguard::{OwnedMutex,OwnedMutexGuard}; // Note the return value has a lifetime distinct from the input fn get_locked<'a,T: Clone>(input: &T) -> LockResult<OwnedMutexGuard<'a,T,Arc<Mutex<T>>>> { Arc::new(Mutex::new(input.clone())).owned_lock() } assert_eq!([0,1,2,3,4,5,6,7,8,9],*get_locked(&[0,1,2,3,4,5,6,7,8,9]).unwrap());
License
OwnedMutexGuard - Copyright (C) 2015 Jethro G. Beekman
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Structs
OwnedMutexGuard |
An RAII implementation of a "scoped lock" of a mutex. When this structure is dropped (falls out of scope), the lock will be unlocked, and the owner of the Mutex will be dropped. |
Traits
OwnedMutex |
Implements the functions to obtain |