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:
bors[bot]
2022-08-29 06:34:17 +00:00
committed by GitHub
7 changed files with 23 additions and 14 deletions

View File

@@ -15,6 +15,7 @@ jobs:
strategy:
matrix:
rust:
- "1.63" # minimum stable rust version
- stable
- beta
- nightly

View File

@@ -6,6 +6,11 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [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
- Update [`parking_lot`][parking_lot] dependency to `0.12`.

View File

@@ -10,6 +10,7 @@ keywords = ["mutex", "rwlock", "once", "thread"]
description = "Ensure deadlock-free mutexes by allocating in order, or else."
readme = "README.md"
repository = "https://github.com/bertptrs/tracing-mutex"
rust-version = "1.63"
[package.metadata.docs.rs]
# Build docs for all features so the documentation is more complete

View File

@@ -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.
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/
[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
@@ -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
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
- Dependency-tracking wrappers for all locking primitives

View File

@@ -1,4 +1,5 @@
status = [
'Rust project (1.63)',
'Rust project (stable)',
'Rust project (beta)',
'Documentation build',

View File

@@ -53,7 +53,6 @@ use std::marker::PhantomData;
use std::mem::MaybeUninit;
use std::ops::Deref;
use std::ops::DerefMut;
use std::ptr;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use std::sync::Mutex;
@@ -271,9 +270,7 @@ impl Drop for LazyMutexId {
// 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.
let mutex_id = unsafe { ptr::read((*self.inner.get()).as_ptr()) };
drop(mutex_id);
unsafe { (*self.inner.get()).assume_init_drop() };
}
}
}

View File

@@ -42,7 +42,6 @@ pub mod tracing {
use crate::BorrowedMutex;
use crate::LazyMutexId;
use crate::MutexId;
/// Wrapper for [`std::sync::Mutex`].
///
@@ -51,7 +50,7 @@ pub mod tracing {
#[derive(Debug, Default)]
pub struct Mutex<T> {
inner: sync::Mutex<T>,
id: MutexId,
id: LazyMutexId,
}
/// Wrapper for [`std::sync::MutexGuard`].
@@ -89,10 +88,10 @@ pub mod tracing {
impl<T> Mutex<T> {
/// Create a new tracing mutex with the provided value.
pub fn new(t: T) -> Self {
pub const fn new(t: T) -> Self {
Self {
inner: sync::Mutex::new(t),
id: MutexId::new(),
id: LazyMutexId::new(),
}
}
@@ -220,8 +219,8 @@ pub mod tracing {
impl Condvar {
/// Creates a new condition variable which is ready to be waited on and notified.
pub fn new() -> Self {
Default::default()
pub const fn new() -> Self {
Self(sync::Condvar::new())
}
/// Wrapper for [`std::sync::Condvar::wait`].
@@ -294,7 +293,7 @@ pub mod tracing {
#[derive(Debug, Default)]
pub struct RwLock<T> {
inner: sync::RwLock<T>,
id: MutexId,
id: LazyMutexId,
}
/// 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>>;
impl<T> RwLock<T> {
pub fn new(t: T) -> Self {
pub const fn new(t: T) -> Self {
Self {
inner: sync::RwLock::new(t),
id: MutexId::new(),
id: LazyMutexId::new(),
}
}