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

Make RawReentrantMutex public #233

Merged
merged 1 commit into from May 19, 2020

Conversation

coolreader18
Copy link
Contributor

This is useful for any use case that you'd be using a raw mutex for, where you also want reentrancy.

@coolreader18
Copy link
Contributor Author

I don't think the android build failure is related to my changes, right?

@coolreader18
Copy link
Contributor Author

Oh, hmm, this isn't sound, since when RawMutex::lock() succeeds Mutex assumes that it's completely exclusive. Maybe there could be another marker type on RawMutex to allow unifying Mutex and ReentrantMutex to the same generic type?

@Amanieu
Copy link
Owner

Amanieu commented May 18, 2020

You're right, you can't implement the RawMutex trait for a reentrant mutex since it would allow you to produce mutable &mut to the same data.

I don't think there is much of a use case for a raw reentrant mutex since you can always use ReentrantMutex<()> instead.

@coolreader18
Copy link
Contributor Author

Maybe ReentrantMutex<()> could expose an API that's similar to RawMutex? Idk, I probably have like the only use case for this that wouldn't need to use unsafe other than maybe ReentrantMutex::force_unlock; I'm implementing a Lock class for python, where all the other data structures are atomic/mutex-backed as well, but the lock is used for synchronization of multiple different operations that might modify multiple different data structures. The current implementation that I'm basing on this branch uses a trait with an associated RawMutex type, and I use that to implement reentrant and non-reentrant locks. I could probably just use a macro, though, or duplicate a bit of code.

@coolreader18
Copy link
Contributor Author

coolreader18 commented May 18, 2020

Maybe RawReentrantMutex could be made public with just the methods from the RawMutex* traits, but not actually implementing them?

@Amanieu
Copy link
Owner

Amanieu commented May 18, 2020

If you really want to expose it publicly then you should keep the methods as they are instead of using traits.

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