Lines Matching full:guard
3 //! Generic kernel lock and guard.
5 //! It contains a generic Rust lock and guard that allow for different backends (e.g., mutexes,
167 pub fn lock(&self) -> Guard<'_, T, B> { in lock()
172 unsafe { Guard::new(self, state) } in lock()
177 /// Returns a guard that can be used to access the data protected by the lock if successful.
180 pub fn try_lock(&self) -> Option<Guard<'_, T, B>> { in try_lock()
183 unsafe { B::try_lock(self.state.get()).map(|state| Guard::new(self, state)) } in try_lock()
187 /// A lock guard.
190 /// when a guard goes out of scope. It also provides a safe and convenient way to access the data
192 #[must_use = "the lock unlocks immediately when the guard is unused"]
193 pub struct Guard<'a, T: ?Sized, B: Backend> { struct
199 // SAFETY: `Guard` is sync when the data protected by the lock is also sync. argument
200 unsafe impl<T: Sync + ?Sized, B: Backend> Sync for Guard<'_, T, B> {} implementation
202 impl<'a, T: ?Sized, B: Backend> Guard<'a, T, B> { implementation
203 /// Returns the lock that this guard originates from.
207 /// The following example shows how to use [`Guard::lock_ref()`] to assert the corresponding
211 /// # use kernel::{new_spinlock, sync::lock::{Backend, Guard, Lock}};
214 /// fn assert_held<T, B: Backend>(guard: &Guard<'_, T, B>, lock: &Lock<T, B>) {
216 /// assert!(core::ptr::eq(guard.lock_ref(), lock));
245 impl<T: ?Sized, B: Backend> core::ops::Deref for Guard<'_, T, B> { implementation
254 impl<T: ?Sized, B: Backend> core::ops::DerefMut for Guard<'_, T, B> { implementation
261 impl<T: ?Sized, B: Backend> Drop for Guard<'_, T, B> { implementation
268 impl<'a, T: ?Sized, B: Backend> Guard<'a, T, B> { impl
269 /// Constructs a new immutable lock guard.