Skip to content

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.

mystor added 2 commits July 26, 2020 15:18
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.

1 participant