Skip to content

Commit d7bcef0

Browse files
authored
Merge pull request #25 from mkroening/arc_lock
feat: add `arc_lock` feature and typedefs
2 parents 9d803fe + cf3aa5c commit d7bcef0

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ license = "MIT/Apache-2.0"
77
description = "A simple spinlock crate based on the abstractions provided by `lock_api`."
88
repository = "https://github.com/rust-osdev/spinning_top"
99

10-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
10+
[package.metadata.docs.rs]
11+
all-features = true
12+
rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]
1113

1214
[features]
15+
arc_lock = ["lock_api/arc_lock"]
1316
owning_ref = ["lock_api/owning_ref"]
1417

1518
[dependencies]

src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
//! ```
5252
5353
#![cfg_attr(not(test), no_std)]
54+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
5455
#![warn(missing_docs)]
5556
#![warn(missing_debug_implementations)]
5657

@@ -62,11 +63,19 @@ pub use spinlock::{BackoffSpinlock, RawSpinlock, Spinlock};
6263

6364
/// Type aliases for guards.
6465
pub mod guard {
66+
#[cfg(feature = "arc_lock")]
67+
pub use super::rw_spinlock::{
68+
ArcBackoffRwSpinlockReadGuard, ArcBackoffRwSpinlockUpgradableReadGuard,
69+
ArcBackoffRwSpinlockWriteGuard, ArcRwSpinlockReadGuard, ArcRwSpinlockUpgradableReadGuard,
70+
ArcRwSpinlockWriteGuard,
71+
};
6572
pub use super::rw_spinlock::{
6673
BackoffRwSpinlockReadGuard, BackoffRwSpinlockUpgradableReadGuard,
6774
BackoffRwSpinlockWriteGuard, RwSpinlockReadGuard, RwSpinlockUpgradableReadGuard,
6875
RwSpinlockWriteGuard,
6976
};
77+
#[cfg(feature = "arc_lock")]
78+
pub use super::spinlock::{ArcBackoffSpinlockGuard, ArcSpinlockGuard};
7079
pub use super::spinlock::{
7180
BackoffSpinlockGuard, MappedBackoffSpinlockGuard, MappedSpinlockGuard, SpinlockGuard,
7281
};

src/rw_spinlock.rs

+27
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,19 @@ pub type RwSpinlockUpgradableReadGuard<'a, T> =
232232
/// A [`lock_api::RwLockWriteGuard`] based on [`RawRwSpinlock`].
233233
pub type RwSpinlockWriteGuard<'a, T> = lock_api::RwLockWriteGuard<'a, RawRwSpinlock<Spin>, T>;
234234

235+
/// A [`lock_api::ArcRwLockReadGuard`] based on [`RawRwSpinlock`].
236+
#[cfg(feature = "arc_lock")]
237+
pub type ArcRwSpinlockReadGuard<T> = lock_api::ArcRwLockReadGuard<RawRwSpinlock<Spin>, T>;
238+
239+
/// A [`lock_api::ArcRwLockUpgradableReadGuard`] based on [`RawRwSpinlock`].
240+
#[cfg(feature = "arc_lock")]
241+
pub type ArcRwSpinlockUpgradableReadGuard<T> =
242+
lock_api::ArcRwLockUpgradableReadGuard<RawRwSpinlock<Spin>, T>;
243+
244+
/// A [`lock_api::ArcRwLockWriteGuard`] based on [`RawRwSpinlock`].
245+
#[cfg(feature = "arc_lock")]
246+
pub type ArcRwSpinlockWriteGuard<T> = lock_api::ArcRwLockWriteGuard<RawRwSpinlock<Spin>, T>;
247+
235248
/// A [`lock_api::RwLock`] based on [`RawRwSpinlock`]`<`[`Backoff`]`>`.
236249
pub type BackoffRwSpinlock<T> = lock_api::RwLock<RawRwSpinlock<Backoff>, T>;
237250

@@ -247,6 +260,20 @@ pub type BackoffRwSpinlockUpgradableReadGuard<'a, T> =
247260
pub type BackoffRwSpinlockWriteGuard<'a, T> =
248261
lock_api::RwLockWriteGuard<'a, RawRwSpinlock<Backoff>, T>;
249262

263+
/// A [`lock_api::ArcRwLockReadGuard`] based on [`RawRwSpinlock`]`<`[`Backoff`]`>`.
264+
#[cfg(feature = "arc_lock")]
265+
pub type ArcBackoffRwSpinlockReadGuard<T> = lock_api::ArcRwLockReadGuard<RawRwSpinlock<Backoff>, T>;
266+
267+
/// A [`lock_api::ArcRwLockUpgradableReadGuard`] based on [`RawRwSpinlock`]`<`[`Backoff`]`>`.
268+
#[cfg(feature = "arc_lock")]
269+
pub type ArcBackoffRwSpinlockUpgradableReadGuard<T> =
270+
lock_api::ArcRwLockUpgradableReadGuard<RawRwSpinlock<Backoff>, T>;
271+
272+
/// A [`lock_api::ArcRwLockWriteGuard`] based on [`RawRwSpinlock`]`<`[`Backoff`]`>`.
273+
#[cfg(feature = "arc_lock")]
274+
pub type ArcBackoffRwSpinlockWriteGuard<T> =
275+
lock_api::ArcRwLockWriteGuard<RawRwSpinlock<Backoff>, T>;
276+
250277
// Adapted from `spin::rwlock`.
251278
#[cfg(test)]
252279
mod tests {

src/spinlock.rs

+8
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ pub type SpinlockGuard<'a, T> = lock_api::MutexGuard<'a, RawSpinlock<Spin>, T>;
202202
/// ```
203203
pub type MappedSpinlockGuard<'a, T> = lock_api::MappedMutexGuard<'a, RawSpinlock<Spin>, T>;
204204

205+
/// A [`lock_api::ArcMutexGuard`] based on [`RawSpinlock`]`.
206+
#[cfg(feature = "arc_lock")]
207+
pub type ArcSpinlockGuard<T> = lock_api::ArcMutexGuard<RawSpinlock<Spin>, T>;
208+
205209
/// A mutual exclusion (Mutex) type based on busy-waiting with exponential backoff.
206210
///
207211
/// Calling `lock` (or `try_lock`) on this type returns a [`BackoffSpinlockGuard`], which
@@ -310,6 +314,10 @@ pub type BackoffSpinlockGuard<'a, T> = lock_api::MutexGuard<'a, RawSpinlock<Back
310314
pub type MappedBackoffSpinlockGuard<'a, T> =
311315
lock_api::MappedMutexGuard<'a, RawSpinlock<Backoff>, T>;
312316

317+
/// A [`lock_api::ArcMutexGuard`] based on [`RawSpinlock`]`<`[`Backoff`]`>`.
318+
#[cfg(feature = "arc_lock")]
319+
pub type ArcBackoffSpinlockGuard<T> = lock_api::ArcMutexGuard<RawSpinlock<Backoff>, T>;
320+
313321
#[cfg(test)]
314322
mod tests {
315323
use super::*;

0 commit comments

Comments
 (0)