Type Definition kernel::sync::RevocableMutex

source · []
pub type RevocableMutex<T> = Revocable<Mutex<()>, T>;
Expand description

A revocable mutex.

That is, a mutex to which access can be revoked at runtime. It is a specialisation of the more generic super::revocable::Revocable.

Examples


struct Example {
    a: u32,
    b: u32,
}

fn read_sum(v: &RevocableMutex<Example>) -> Option<u32> {
    let guard = v.try_write()?;
    Some(guard.a + guard.b)
}

// SAFETY: We call `revocable_init` immediately below.
let mut v = unsafe { RevocableMutex::new(Example { a: 10, b: 20 }) };
// SAFETY: We never move out of `v`.
let pinned = unsafe { Pin::new_unchecked(&mut v) };
revocable_init!(pinned, "example::v");
assert_eq!(read_sum(&v), Some(30));
v.revoke();
assert_eq!(read_sum(&v), None);
This documentation is an old archive. Please see https://rust.docs.kernel.org instead.