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
sourceimpl<T> Revocable<T>
impl<T> Revocable<T>
sourcepub fn try_access(&self) -> Option<RevocableGuard<'_, T>>
pub fn try_access(&self) -> Option<RevocableGuard<'_, T>>
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.
sourcepub fn try_access_with_guard<'a>(&'a self, _guard: &'a Guard) -> Option<&'a T>
pub fn try_access_with_guard<'a>(&'a self, _guard: &'a Guard) -> Option<&'a T>
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.
sourcepub fn revoke(&self)
pub fn revoke(&self)
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.