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 support for lock_api #161

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add support for lock_api #161

wants to merge 2 commits into from

Conversation

mystor
Copy link

@mystor mystor commented Jul 26, 2020

Adds Loom mock implementations of the lock_api::RawMutex and lock_api::RawRwLock traits, as well as re-exports for the relevant concrete types, gated behind a "lock_api" feature.

The parking_lot and lock_api crates provide a slightly different interface than the standard library interface to Mutex and RwLock, which can make them difficult or impossible to test using sync::Mutex and sync::RwLock mocks.

Adds Loom mock implementations of the `lock_api::RawMutex` and
`lock_api::RawRwLock` traits, as well as re-exports for the relevant concrete
types, gated behind a `"lock_api"` feature.

The `parking_lot` and `lock_api` crates provide a slightly different interface
than the standard library interface to `Mutex` and `RwLock`, which can make them
difficult or impossible to test using `sync::Mutex` and `sync::RwLock` mocks.
Comment on lines +17 to +22
// Unfortunately, we're required to have a `const INIT` in order to
// implement `lock_api::RawMutex`, so we need to lazily create the actual
// `rt::Mutex`.
fn object(&self) -> &rt::Mutex {
self.object.get_or_init(|| rt::Mutex::new(true))
}
Copy link
Author

Choose a reason for hiding this comment

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

I couldn't think of a cleaner way to satisfy this requirement, so I threw in a OnceCell.

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

1 participant