Skip to content
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

Add a rwlock method to report if lock is held exclusively #303

Merged
merged 2 commits into from Nov 4, 2021
Merged

Add a rwlock method to report if lock is held exclusively #303

merged 2 commits into from Nov 4, 2021

Conversation

declanvk
Copy link
Contributor

@declanvk declanvk commented Nov 4, 2021

Closes issue #293.

I also ran into the same issue posed in issue #293. Specifically, it was
for implementing an optimistic hybrid lock as described in this paper
in section 2.3, listing #2.

@Amanieu
Copy link
Owner

Amanieu commented Nov 4, 2021

I think you could add a default implementation in the trait which attempts to get a shared lock. This should only fail if there is an active exclusive lock. The default implementation is needed to maintain backwards compatibility with existing implementations of this trait.

@declanvk
Copy link
Contributor Author

declanvk commented Nov 4, 2021

I think you could add a default implementation in the trait which attempts to get a shared lock. This should only fail if there is an active exclusive lock. The default implementation is needed to maintain backwards compatibility with existing implementations of this trait.

I'll add that to the trait definition. To test for an exclusive lock, would it look something like:

    fn is_locked_exclusive(&self) -> bool {
        let acquired_lock = self.try_lock_shared();
        if acquired_lock {
            // Safety: A shared lock was successfully acquired above.
            unsafe {
                self.unlock_shared();
            }
        }
        !acquired_lock
    }

to parallel the existing is_locked default implementation?

@Amanieu
Copy link
Owner

Amanieu commented Nov 4, 2021

That's correct.

This ensures backwards compatibility with existing implementations
of the RawRwLock trait.
@Amanieu Amanieu merged commit f9e5673 into Amanieu:master Nov 4, 2021
@declanvk declanvk deleted the is-locked-excl branch November 5, 2021 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants