pub struct ThreadOwnedLock<T: ?Sized, P: ThreadIdProvider> { /* private fields */ }Expand description
Implementations§
Source§impl<T, P: ThreadIdProvider> ThreadOwnedLock<T, P>
impl<T, P: ThreadIdProvider> ThreadOwnedLock<T, P>
Sourcepub fn new(value: T) -> Self
pub fn new(value: T) -> Self
Create a new instance of ThreadOwnedLock and bind it to the current thread.
Sourcepub fn rebind(self) -> Self
pub fn rebind(self) -> Self
Transfer ownership of the lock to another thread.
§Example
use thread_owned_lock::StdThreadOwnedLock;
let lock = StdThreadOwnedLock::new(10);
std::thread::spawn(move|| {
let lock = lock.rebind();
// lock can now be accessed on this thread.
let guard = lock.lock();
});Source§impl<T: ?Sized, P: ThreadIdProvider> ThreadOwnedLock<T, P>
impl<T: ?Sized, P: ThreadIdProvider> ThreadOwnedLock<T, P>
Sourcepub fn lock(&self) -> ThreadOwnedLockGuard<'_, T, P>
pub fn lock(&self) -> ThreadOwnedLockGuard<'_, T, P>
Acquires the mutex, returning an RAII style guard which allows access to the data.
§Panics
This call will panic if this method is called from a thread other than the owning thread or if the lock has already been acquired.
Sourcepub fn try_lock(
&self,
) -> Result<ThreadOwnedLockGuard<'_, T, P>, ThreadOwnedMutexError>
pub fn try_lock( &self, ) -> Result<ThreadOwnedLockGuard<'_, T, P>, ThreadOwnedMutexError>
Try to acquire the mutex. If one of the following conditions fails, an error will be returned:
- The thread accessing the lock must be the bound thread.
- The lock can only be acquired on time.
Trait Implementations§
Source§impl<T: Default, P: ThreadIdProvider> Default for ThreadOwnedLock<T, P>
impl<T: Default, P: ThreadIdProvider> Default for ThreadOwnedLock<T, P>
Source§impl<T, P: ThreadIdProvider> From<T> for ThreadOwnedLock<T, P>
impl<T, P: ThreadIdProvider> From<T> for ThreadOwnedLock<T, P>
impl<T: ?Sized + Send, P: ThreadIdProvider> Send for ThreadOwnedLock<T, P>
impl<T: ?Sized + Send, P: ThreadIdProvider> Sync for ThreadOwnedLock<T, P>
Auto Trait Implementations§
impl<T, P> !Freeze for ThreadOwnedLock<T, P>
impl<T, P> !RefUnwindSafe for ThreadOwnedLock<T, P>
impl<T, P> Unpin for ThreadOwnedLock<T, P>
impl<T, P> UnwindSafe for ThreadOwnedLock<T, P>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more