pub struct Revocable<T> { /* private fields */ }
Expand description

An object that can become inaccessible at runtime.

Once access is revoked and all concurrent users complete (i.e., all existing instances of RevocableGuard are dropped), the wrapped object is also dropped.

Examples


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

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

let v = Revocable::new(Example { a: 10, b: 20 });
assert_eq!(add_two(&v), Some(30));
v.revoke();
assert_eq!(add_two(&v), None);

Sample example as above, but explicitly using the rcu read side lock.

use kernel::sync::rcu;

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

fn add_two(v: &Revocable<Example>) -> Option<u32> {
    let guard = rcu::read_lock();
    let e = v.try_access_with_guard(&guard)?;
    Some(e.a + e.b)
}

let v = Revocable::new(Example { a: 10, b: 20 });
assert_eq!(add_two(&v), Some(30));
v.revoke();
assert_eq!(add_two(&v), None);

Implementations

Creates a new revocable instance of the given data.

Tries to access the [revocable] wrapped object.

Returns None if the object has been revoked and is therefore no longer accessible.

Returns a guard that gives access to the object otherwise; the object is guaranteed to remain accessible while the guard is alive. In such cases, callers are not allowed to sleep because another CPU may be waiting to complete the revocation of this object.

Tries to access the [revocable] wrapped object.

Returns None if the object has been revoked and is therefore no longer accessible.

Returns a shared reference to the object otherwise; the object is guaranteed to remain accessible while the rcu read side guard is alive. In such cases, callers are not allowed to sleep because another CPU may be waiting to complete the revocation of this object.

Revokes access to and drops the wrapped object.

Access to the object is revoked immediately to new callers of Revocable::try_access. If there are concurrent users of the object (i.e., ones that called Revocable::try_access beforehand and still haven’t dropped the returned guard), this function waits for the concurrent access to complete before dropping the wrapped object.

Trait Implementations

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

This documentation is an old archive. Please see https://rust.docs.kernel.org instead.