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 MappedArcMutexGuard to mirror MappedMutexGuard #457

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dflemstr
Copy link

@dflemstr dflemstr commented Jan 13, 2025

Add a new type, MappedArcMutexGuard, that mirrors the API of MappedMutexGuard but with an owned Arc<> reference to the underlying mutex while locked.

I didn't find any tests covering MappedMutexGuard, so I didn't change the status quo. Instead, I copied the exact same implementation as for MappedMutexGuard but with lifetimes removed and &'a R references to the raw mutex replaced with Arc<Mutex<T, R>>. I believe this should make the new type at least as sound as the previous MappedMutexGuard.

Unfortunately, since we only have an Arc around Mutex, but not the raw mutex type R, we cannot type erase the wrapped mutex and need to retain the original type T in MappedArcMutexGuard<R, T, U> (as opposed to MappedArcMutexGuard<R, U>).

The name was chosen based on the existing pattern of MappedFairMutexGuard to arrive at MappedArcMutexGuard (as opposed to e.g. ArcMappedMutexGuard or whatever).

@dflemstr
Copy link
Author

I'm going to iterate a bit on the implementation of this PR and test it in various tricky production cases to make sure it is sound, so moving into Draft state

@dflemstr dflemstr marked this pull request as draft January 13, 2025 11:22
@dflemstr dflemstr force-pushed the dflemstr/mapped-arc-mutex-guard branch from 412586c to 9cd6b13 Compare January 13, 2025 11:34
@dflemstr dflemstr changed the title lock_api: Add MappedArcMutexGuard to mirror MappedMutexGuard Add MappedArcMutexGuard to mirror MappedMutexGuard Jan 13, 2025
@dflemstr dflemstr force-pushed the dflemstr/mapped-arc-mutex-guard branch 2 times, most recently from d12c8eb to ae19232 Compare January 13, 2025 11:43
@dflemstr dflemstr force-pushed the dflemstr/mapped-arc-mutex-guard branch from ae19232 to 7c352e6 Compare January 13, 2025 11:44
@dflemstr dflemstr marked this pull request as ready for review January 14, 2025 08:14
@dflemstr
Copy link
Author

Gonna do some more testing but I think this PR is ready to get new eyes on it.

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.

1 participant