pub struct LockClassKey { /* private fields */ }Expand description
Represents a lockdep class.
Wraps the kernel’s struct lock_class_key.
Implementations§
Source§impl LockClassKey
impl LockClassKey
Source§impl LockClassKey
impl LockClassKey
Sourcepub const unsafe fn new_static() -> Self
pub const unsafe fn new_static() -> Self
Initializes a statically allocated lock class key.
This is usually used indirectly through the static_lock_class! macro. See its
documentation for more information.
§Safety
- Before using the returned value, it must be pinned in a static memory location.
- The destructor must never run on the returned
LockClassKey.
Sourcepub fn new_dynamic() -> impl PinInit<Self>
pub fn new_dynamic() -> impl PinInit<Self>
Initializes a dynamically allocated lock class key.
In the common case of using a statically allocated lock class key, the
static_lock_class! macro should be used instead.
§Examples
use kernel::alloc::KBox;
use kernel::types::ForeignOwnable;
use kernel::sync::{LockClassKey, SpinLock};
use pin_init::stack_pin_init;
let key = KBox::pin_init(LockClassKey::new_dynamic(), GFP_KERNEL)?;
let key_ptr = key.into_foreign();
{
stack_pin_init!(let num: SpinLock<u32> = SpinLock::new(
0,
c"my_spinlock",
// SAFETY: `key_ptr` is returned by the above `into_foreign()`, whose
// `from_foreign()` has not yet been called.
unsafe { <Pin<KBox<LockClassKey>> as ForeignOwnable>::borrow(key_ptr) }
));
}
// SAFETY: We dropped `num`, the only use of the key, so the result of the previous
// `borrow` has also been dropped. Thus, it's safe to use from_foreign.
unsafe { drop(<Pin<KBox<LockClassKey>> as ForeignOwnable>::from_foreign(key_ptr)) };Trait Implementations§
Source§impl Drop for LockClassKey
impl Drop for LockClassKey
Source§impl HasPinData for LockClassKey
impl HasPinData for LockClassKey
Source§impl PinnedDrop for LockClassKey
impl PinnedDrop for LockClassKey
impl Send for LockClassKey
impl Sync for LockClassKey
Auto Trait Implementations§
impl !Freeze for LockClassKey
impl !RefUnwindSafe for LockClassKey
impl UnwindSafe for LockClassKey
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
Source§impl<T> PinInit<T> for T
impl<T> PinInit<T> for T
Source§unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
Initializes
slot. Read more