Skip to content

rust: add RevocableMutex. #569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2021
Merged

Conversation

wedsonaf
Copy link

This is a mutex where access to its contents can be revoked at runtime.
This is different from Revocable in a few ways:

  1. The caller may sleep while holding a guard.
  2. Accessors are all serialised.
  3. Accessing is not as cheap (because it involves acquiring the mutex).
  4. The size of the object is larger (because it involves a mutex +
    flag).

An example of where this a good fit to be used in device state that
holds registrations to other subsystems, for example, the PL061 driver
registers with the gpio subsystem; the registration is only used on
probe and is revoked on remove.

Signed-off-by: Wedson Almeida Filho [email protected]

This is a mutex where access to its contents can be revoked at runtime.
This is different from `Revocable` in a few ways:
1. The caller may sleep while holding a guard.
2. Accessors are all serialised.
3. Accessing is not as cheap (because it involves acquiring the mutex).
4. The size of the object is larger (because it involves a mutex +
flag).

An example of where this a good fit to be used in device state that
holds registrations to other subsystems, for example, the PL061 driver
registers with the gpio subsystem; the registration is only used on
`probe` and is revoked on `remove`.

Signed-off-by: Wedson Almeida Filho <[email protected]>
///
/// Revocation and dropping happens after ongoing accessors complete.
pub fn revoke(&self) {
let mut inner = self.inner.lock();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to have .revoke() set an atomic flag that signals revocation and only drop the inner value if the mutex isn't locke and otherwise let the mutex guard drop it when dropping?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon return from revoke, we want to ensure that the inner value has been dropped.

This is because the scenario where this is used at the moment is when remove is called on a device: we want all io resources and registrations to be dropped before returning (to ensure that they won't be used again).

If we were to do as you suggest, we could get into a situation where, for example, a GPIO is still exposed to userspace even though the device has already been removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

@wedsonaf wedsonaf merged commit 0028943 into Rust-for-Linux:rust Nov 27, 2021
@wedsonaf wedsonaf deleted the revocable-mutex branch November 27, 2021 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants