mirror of
https://github.com/bertptrs/tracing-mutex.git
synced 2025-12-25 20:50:32 +01:00
Merge #27
27: Add MSRV of 1.63 r=bertptrs a=bertptrs Fixes #26. Co-authored-by: Bert Peters <bert@bertptrs.nl>
This commit is contained in:
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@@ -15,6 +15,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
rust:
|
rust:
|
||||||
|
- "1.63" # minimum stable rust version
|
||||||
- stable
|
- stable
|
||||||
- beta
|
- beta
|
||||||
- nightly
|
- nightly
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- The minimum supported Rust version is now defined as 1.63. Previously it was undefined.
|
||||||
|
- Wrappers for `std::sync` primitives can now be `const` constructed.
|
||||||
|
|
||||||
### Breaking
|
### Breaking
|
||||||
|
|
||||||
- Update [`parking_lot`][parking_lot] dependency to `0.12`.
|
- Update [`parking_lot`][parking_lot] dependency to `0.12`.
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ keywords = ["mutex", "rwlock", "once", "thread"]
|
|||||||
description = "Ensure deadlock-free mutexes by allocating in order, or else."
|
description = "Ensure deadlock-free mutexes by allocating in order, or else."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
repository = "https://github.com/bertptrs/tracing-mutex"
|
repository = "https://github.com/bertptrs/tracing-mutex"
|
||||||
|
rust-version = "1.63"
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
# Build docs for all features so the documentation is more complete
|
# Build docs for all features so the documentation is more complete
|
||||||
|
|||||||
@@ -23,10 +23,12 @@ tree out of it, and panics if your dependencies would create a cycle. It provide
|
|||||||
existing synchronization primitives with an identical API, and should be a drop-in replacement.
|
existing synchronization primitives with an identical API, and should be a drop-in replacement.
|
||||||
|
|
||||||
Inspired by [this blogpost][whileydave], which references a similar behaviour implemented by
|
Inspired by [this blogpost][whileydave], which references a similar behaviour implemented by
|
||||||
[Abseil][abseil-mutex] for their mutexes.
|
[Abseil][abseil-mutex] for their mutexes. [This article goes into more depth on the exact
|
||||||
|
implementation.][article]
|
||||||
|
|
||||||
[whileydave]: https://whileydave.com/2020/12/19/dynamic-cycle-detection-for-lock-ordering/
|
[whileydave]: https://whileydave.com/2020/12/19/dynamic-cycle-detection-for-lock-ordering/
|
||||||
[abseil-mutex]: https://abseil.io/docs/cpp/guides/synchronization
|
[abseil-mutex]: https://abseil.io/docs/cpp/guides/synchronization
|
||||||
|
[article]: https://bertptrs.nl/2022/06/23/deadlock-free-mutexes-and-directed-acyclic-graphs.html
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@@ -59,6 +61,9 @@ performance penalty in your production environment, this library also offers deb
|
|||||||
when debug assertions are enabled, and to `Mutex` when they are not. Similar helper types are
|
when debug assertions are enabled, and to `Mutex` when they are not. Similar helper types are
|
||||||
available for other synchronization primitives.
|
available for other synchronization primitives.
|
||||||
|
|
||||||
|
The minimum supported Rust version is 1.63. Increasing this is not considered a breaking change, but
|
||||||
|
will be avoided within semver-compatible releases if possible.
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- Dependency-tracking wrappers for all locking primitives
|
- Dependency-tracking wrappers for all locking primitives
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
status = [
|
status = [
|
||||||
|
'Rust project (1.63)',
|
||||||
'Rust project (stable)',
|
'Rust project (stable)',
|
||||||
'Rust project (beta)',
|
'Rust project (beta)',
|
||||||
'Documentation build',
|
'Documentation build',
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ use std::marker::PhantomData;
|
|||||||
use std::mem::MaybeUninit;
|
use std::mem::MaybeUninit;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
use std::ptr;
|
|
||||||
use std::sync::atomic::AtomicUsize;
|
use std::sync::atomic::AtomicUsize;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
@@ -271,9 +270,7 @@ impl Drop for LazyMutexId {
|
|||||||
// We have a valid mutex ID and need to drop it
|
// We have a valid mutex ID and need to drop it
|
||||||
|
|
||||||
// Safety: we know that this pointer is valid because the initializer has successfully run.
|
// Safety: we know that this pointer is valid because the initializer has successfully run.
|
||||||
let mutex_id = unsafe { ptr::read((*self.inner.get()).as_ptr()) };
|
unsafe { (*self.inner.get()).assume_init_drop() };
|
||||||
|
|
||||||
drop(mutex_id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ pub mod tracing {
|
|||||||
|
|
||||||
use crate::BorrowedMutex;
|
use crate::BorrowedMutex;
|
||||||
use crate::LazyMutexId;
|
use crate::LazyMutexId;
|
||||||
use crate::MutexId;
|
|
||||||
|
|
||||||
/// Wrapper for [`std::sync::Mutex`].
|
/// Wrapper for [`std::sync::Mutex`].
|
||||||
///
|
///
|
||||||
@@ -51,7 +50,7 @@ pub mod tracing {
|
|||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Mutex<T> {
|
pub struct Mutex<T> {
|
||||||
inner: sync::Mutex<T>,
|
inner: sync::Mutex<T>,
|
||||||
id: MutexId,
|
id: LazyMutexId,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wrapper for [`std::sync::MutexGuard`].
|
/// Wrapper for [`std::sync::MutexGuard`].
|
||||||
@@ -89,10 +88,10 @@ pub mod tracing {
|
|||||||
|
|
||||||
impl<T> Mutex<T> {
|
impl<T> Mutex<T> {
|
||||||
/// Create a new tracing mutex with the provided value.
|
/// Create a new tracing mutex with the provided value.
|
||||||
pub fn new(t: T) -> Self {
|
pub const fn new(t: T) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inner: sync::Mutex::new(t),
|
inner: sync::Mutex::new(t),
|
||||||
id: MutexId::new(),
|
id: LazyMutexId::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,8 +219,8 @@ pub mod tracing {
|
|||||||
|
|
||||||
impl Condvar {
|
impl Condvar {
|
||||||
/// Creates a new condition variable which is ready to be waited on and notified.
|
/// Creates a new condition variable which is ready to be waited on and notified.
|
||||||
pub fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Default::default()
|
Self(sync::Condvar::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wrapper for [`std::sync::Condvar::wait`].
|
/// Wrapper for [`std::sync::Condvar::wait`].
|
||||||
@@ -294,7 +293,7 @@ pub mod tracing {
|
|||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct RwLock<T> {
|
pub struct RwLock<T> {
|
||||||
inner: sync::RwLock<T>,
|
inner: sync::RwLock<T>,
|
||||||
id: MutexId,
|
id: LazyMutexId,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Hybrid wrapper for both [`std::sync::RwLockReadGuard`] and [`std::sync::RwLockWriteGuard`].
|
/// Hybrid wrapper for both [`std::sync::RwLockReadGuard`] and [`std::sync::RwLockWriteGuard`].
|
||||||
@@ -312,10 +311,10 @@ pub mod tracing {
|
|||||||
pub type RwLockWriteGuard<'a, T> = TracingRwLockGuard<'a, sync::RwLockWriteGuard<'a, T>>;
|
pub type RwLockWriteGuard<'a, T> = TracingRwLockGuard<'a, sync::RwLockWriteGuard<'a, T>>;
|
||||||
|
|
||||||
impl<T> RwLock<T> {
|
impl<T> RwLock<T> {
|
||||||
pub fn new(t: T) -> Self {
|
pub const fn new(t: T) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inner: sync::RwLock::new(t),
|
inner: sync::RwLock::new(t),
|
||||||
id: MutexId::new(),
|
id: LazyMutexId::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user