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.
178 pub fn try_lock(&self) -> Option<Guard<'_, T, B>> { in try_lock()
181 unsafe { B::try_lock(self.state.get()).map(|state| Guard::new(self, state)) } in try_lock()
185 /// A lock guard.
188 /// when a guard goes out of scope. It also provides a safe and convenient way to access the data
190 #[must_use = "the lock unlocks immediately when the guard is unused"]
191 pub struct Guard<'a, T: ?Sized, B: Backend> { struct
197 // SAFETY: `Guard` is sync when the data protected by the lock is also sync. argument
198 unsafe impl<T: Sync + ?Sized, B: Backend> Sync for Guard<'_, T, B> {} implementation
200 impl<'a, T: ?Sized, B: Backend> Guard<'a, T, B> { impl
201 /// Returns the lock that this guard originates from.
205 /// The following example shows how to use [`Guard::lock_ref()`] to assert the corresponding
209 /// # use kernel::{new_spinlock, sync::lock::{Backend, Guard, Lock}};
212 /// fn assert_held<T, B: Backend>(guard: &Guard<'_, T, B>, lock: &Lock<T, B>) {
214 /// assert!(core::ptr::eq(guard.lock_ref(), lock));
243 impl<T: ?Sized, B: Backend> core::ops::Deref for Guard<'_, T, B> { implementation
252 impl<T: ?Sized, B: Backend> core::ops::DerefMut for Guard<'_, T, B> { implementation
259 impl<T: ?Sized, B: Backend> Drop for Guard<'_, T, B> { implementation
266 impl<'a, T: ?Sized, B: Backend> Guard<'a, T, B> { impl
267 /// Constructs a new immutable lock guard.