pub type RevocableRwSemaphore<T> = Revocable<RwSemaphore<()>, T>;
Expand description

A revocable rw semaphore.

That is, a read/write semaphore 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: &RevocableRwSemaphore<Example>) -> Option<u32> {
    let guard = v.try_read()?;
    Some(guard.a + guard.b)
}

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

// SAFETY: We call `revocable_init` immediately below.
let mut v = unsafe { RevocableRwSemaphore::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));
assert_eq!(add_two(&v), Some(34));
v.revoke();
assert_eq!(read_sum(&v), None);
assert_eq!(add_two(&v), None);
This documentation is an old archive. Please see https://rust.docs.kernel.org instead.