Skip to content

Commit b62d1f5

Browse files
committed
Address the review comments
This splits the doc comments into multiple paragraphs and renames the helpers to create the locking primitives to `const_*` instead of `new_*`.
1 parent c20495b commit b62d1f5

File tree

8 files changed

+35
-30
lines changed

8 files changed

+35
-30
lines changed

lock_api/src/mutex.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ impl<R: RawMutex, T> Mutex<R, T> {
132132
}
133133

134134
impl<R, T> Mutex<R, T> {
135-
/// Creates a new mutex based on a pre-existing raw mutex. This allows
136-
/// creating a mutex in a constant context on stable Rust.
135+
/// Creates a new mutex based on a pre-existing raw mutex.
136+
///
137+
/// This allows creating a mutex in a constant context on stable Rust.
137138
#[inline]
138139
pub const fn const_new(raw_mutex: R, val: T) -> Mutex<R, T> {
139140
Mutex {

lock_api/src/remutex.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,21 +198,19 @@ impl<R: RawMutex, G: GetThreadId, T> ReentrantMutex<R, G, T> {
198198
}
199199

200200
impl<R, G, T> ReentrantMutex<R, G, T> {
201-
/// Creates a new reentrant mutex based on a pre-existing raw reentrant
202-
/// mutex and a helper to get the thread ID. This allows creating a
203-
/// reentrant mutex in a constant context on stable Rust.
204-
#[inline]
205-
pub const fn const_new(
206-
raw_reentrant_mutex: R,
207-
get_thread_id: G,
208-
val: T,
209-
) -> ReentrantMutex<R, G, T> {
201+
/// Creates a new reentrant mutex based on a pre-existing raw mutex and a
202+
/// helper to get the thread ID.
203+
///
204+
/// This allows creating a reentrant mutex in a constant context on stable
205+
/// Rust.
206+
#[inline]
207+
pub const fn const_new(raw_mutex: R, get_thread_id: G, val: T) -> ReentrantMutex<R, G, T> {
210208
ReentrantMutex {
211209
data: UnsafeCell::new(val),
212210
raw: RawReentrantMutex {
213211
owner: AtomicUsize::new(0),
214212
lock_count: Cell::new(0),
215-
mutex: raw_reentrant_mutex,
213+
mutex: raw_mutex,
216214
get_thread_id,
217215
},
218216
}

lock_api/src/rwlock.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,10 @@ impl<R: RawRwLock, T> RwLock<R, T> {
299299

300300
impl<R, T> RwLock<R, T> {
301301
/// Creates a new new instance of an `RwLock<T>` based on a pre-existing
302-
/// `RawRwLock<T>`. This allows creating a `RwLock<T>` in a constant context
303-
/// on stable Rust.
302+
/// `RawRwLock<T>`.
303+
///
304+
/// This allows creating a `RwLock<T>` in a constant context on stable
305+
/// Rust.
304306
#[inline]
305307
pub const fn const_new(raw_rwlock: R, val: T) -> RwLock<R, T> {
306308
RwLock {

src/fair_mutex.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ use lock_api;
8080
/// ```
8181
pub type FairMutex<T> = lock_api::Mutex<RawFairMutex, T>;
8282

83-
/// Creates a new fair mutex in an unlocked state ready for use. This allows
84-
/// creating a fair mutex in a constant context on stable Rust.
85-
pub const fn new_fair_mutex<T>(val: T) -> FairMutex<T> {
83+
/// Creates a new fair mutex in an unlocked state ready for use.
84+
///
85+
/// This allows creating a fair mutex in a constant context on stable Rust.
86+
pub const fn const_fair_mutex<T>(val: T) -> FairMutex<T> {
8687
FairMutex::const_new(<RawFairMutex as lock_api::RawMutex>::INIT, val)
8788
}
8889

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ pub mod deadlock;
3131
mod deadlock;
3232

3333
pub use self::condvar::{Condvar, WaitTimeoutResult};
34-
pub use self::fair_mutex::{new_fair_mutex, FairMutex, FairMutexGuard, MappedFairMutexGuard};
35-
pub use self::mutex::{new_mutex, MappedMutexGuard, Mutex, MutexGuard};
34+
pub use self::fair_mutex::{const_fair_mutex, FairMutex, FairMutexGuard, MappedFairMutexGuard};
35+
pub use self::mutex::{const_mutex, MappedMutexGuard, Mutex, MutexGuard};
3636
pub use self::once::{Once, OnceState};
3737
pub use self::raw_fair_mutex::RawFairMutex;
3838
pub use self::raw_mutex::RawMutex;
3939
pub use self::raw_rwlock::RawRwLock;
4040
pub use self::remutex::{
41-
new_reentrant_mutex, MappedReentrantMutexGuard, RawThreadId, ReentrantMutex,
41+
const_reentrant_mutex, MappedReentrantMutexGuard, RawThreadId, ReentrantMutex,
4242
ReentrantMutexGuard,
4343
};
4444
pub use self::rwlock::{
45-
new_rwlock, MappedRwLockReadGuard, MappedRwLockWriteGuard, RwLock, RwLockReadGuard,
45+
const_rwlock, MappedRwLockReadGuard, MappedRwLockWriteGuard, RwLock, RwLockReadGuard,
4646
RwLockUpgradableReadGuard, RwLockWriteGuard,
4747
};
4848
pub use ::lock_api;

src/mutex.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ use lock_api;
8686
/// ```
8787
pub type Mutex<T> = lock_api::Mutex<RawMutex, T>;
8888

89-
/// Creates a new mutex in an unlocked state ready for use. This allows creating
90-
/// a mutex in a constant context on stable Rust.
91-
pub const fn new_mutex<T>(val: T) -> Mutex<T> {
89+
/// Creates a new mutex in an unlocked state ready for use.
90+
///
91+
/// This allows creating a mutex in a constant context on stable Rust.
92+
pub const fn const_mutex<T>(val: T) -> Mutex<T> {
9293
Mutex::const_new(<RawMutex as lock_api::RawMutex>::INIT, val)
9394
}
9495

src/remutex.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ unsafe impl GetThreadId for RawThreadId {
4040
/// primitive.
4141
pub type ReentrantMutex<T> = lock_api::ReentrantMutex<RawMutex, RawThreadId, T>;
4242

43-
/// Creates a new reentrant mutex in an unlocked state ready for use. This
44-
/// allows creating a reentrant mutex in a constant context on stable Rust.
45-
pub const fn new_reentrant_mutex<T>(val: T) -> ReentrantMutex<T> {
43+
/// Creates a new reentrant mutex in an unlocked state ready for use.
44+
///
45+
/// This allows creating a reentrant mutex in a constant context on stable Rust.
46+
pub const fn const_reentrant_mutex<T>(val: T) -> ReentrantMutex<T> {
4647
ReentrantMutex::const_new(
4748
<RawMutex as lock_api::RawMutex>::INIT,
4849
<RawThreadId as lock_api::GetThreadId>::INIT,

src/rwlock.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ use lock_api;
8888
/// ```
8989
pub type RwLock<T> = lock_api::RwLock<RawRwLock, T>;
9090

91-
/// Creates a new instance of an `RwLock<T>` which is unlocked. This allows
92-
/// creating a `RwLock<T>` in a constant context on stable Rust.
93-
pub const fn new_rwlock<T>(val: T) -> RwLock<T> {
91+
/// Creates a new instance of an `RwLock<T>` which is unlocked.
92+
///
93+
/// This allows creating a `RwLock<T>` in a constant context on stable Rust.
94+
pub const fn const_rwlock<T>(val: T) -> RwLock<T> {
9495
RwLock::const_new(<RawRwLock as lock_api::RawRwLock>::INIT, val)
9596
}
9697

0 commit comments

Comments
 (0)