Skip to content

Commit fa80487

Browse files
joboetgitbot
authored and
gitbot
committed
std: clarify comments about initialization
1 parent 5702430 commit fa80487

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

std/src/sys/pal/unix/sync/condvar.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ impl Condvar {
2323
}
2424

2525
/// # Safety
26-
/// `init` must have been called.
26+
/// `init` must have been called on this instance.
2727
#[inline]
2828
pub unsafe fn notify_one(self: Pin<&Self>) {
2929
let r = unsafe { libc::pthread_cond_signal(self.raw()) };
3030
debug_assert_eq!(r, 0);
3131
}
3232

3333
/// # Safety
34-
/// `init` must have been called.
34+
/// `init` must have been called on this instance.
3535
#[inline]
3636
pub unsafe fn notify_all(self: Pin<&Self>) {
3737
let r = unsafe { libc::pthread_cond_broadcast(self.raw()) };
3838
debug_assert_eq!(r, 0);
3939
}
4040

4141
/// # Safety
42-
/// * `init` must have been called.
42+
/// * `init` must have been called on this instance.
4343
/// * `mutex` must be locked by the current thread.
4444
/// * This condition variable may only be used with the same mutex.
4545
#[inline]
@@ -49,7 +49,7 @@ impl Condvar {
4949
}
5050

5151
/// # Safety
52-
/// * `init` must have been called.
52+
/// * `init` must have been called on this instance.
5353
/// * `mutex` must be locked by the current thread.
5454
/// * This condition variable may only be used with the same mutex.
5555
pub unsafe fn wait_timeout(&self, mutex: Pin<&Mutex>, dur: Duration) -> bool {
@@ -95,7 +95,7 @@ impl Condvar {
9595
const CLOCK: libc::clockid_t = libc::CLOCK_MONOTONIC;
9696

9797
/// # Safety
98-
/// May only be called once.
98+
/// May only be called once per instance of `Self`.
9999
pub unsafe fn init(self: Pin<&mut Self>) {
100100
use crate::mem::MaybeUninit;
101101

@@ -137,7 +137,7 @@ impl Condvar {
137137
const CLOCK: libc::clockid_t = libc::CLOCK_REALTIME;
138138

139139
/// # Safety
140-
/// May only be called once.
140+
/// May only be called once per instance of `Self`.
141141
pub unsafe fn init(self: Pin<&mut Self>) {
142142
if cfg!(any(target_os = "espidf", target_os = "horizon", target_os = "teeos")) {
143143
// NOTE: ESP-IDF's PTHREAD_COND_INITIALIZER support is not released yet

std/src/sys/pal/unix/sync/mutex.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl Mutex {
1818
}
1919

2020
/// # Safety
21-
/// Must only be called once.
21+
/// May only be called once per instance of `Self`.
2222
pub unsafe fn init(self: Pin<&mut Self>) {
2323
// Issue #33770
2424
//
@@ -58,7 +58,8 @@ impl Mutex {
5858
}
5959

6060
/// # Safety
61-
/// * If `init` was not called, reentrant locking causes undefined behaviour.
61+
/// * If `init` was not called on this instance, reentrant locking causes
62+
/// undefined behaviour.
6263
/// * Destroying a locked mutex causes undefined behaviour.
6364
pub unsafe fn lock(self: Pin<&Self>) {
6465
#[cold]
@@ -82,7 +83,8 @@ impl Mutex {
8283
}
8384

8485
/// # Safety
85-
/// * If `init` was not called, reentrant locking causes undefined behaviour.
86+
/// * If `init` was not called on this instance, reentrant locking causes
87+
/// undefined behaviour.
8688
/// * Destroying a locked mutex causes undefined behaviour.
8789
pub unsafe fn try_lock(self: Pin<&Self>) -> bool {
8890
unsafe { libc::pthread_mutex_trylock(self.raw()) == 0 }

std/src/sys/sync/condvar/pthread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Condvar {
2222
fn get(&self) -> Pin<&pal::Condvar> {
2323
self.cvar.get_or_init(|| {
2424
let mut cvar = Box::pin(pal::Condvar::new());
25-
// SAFETY: we only call `init` once, namely here.
25+
// SAFETY: we only call `init` once per `pal::Condvar`, namely here.
2626
unsafe { cvar.as_mut().init() };
2727
cvar
2828
})

std/src/sys/sync/mutex/pthread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl Mutex {
2121
// This is sound however, as it cannot have been locked.
2222
self.pal.get_or_init(|| {
2323
let mut pal = Box::pin(pal::Mutex::new());
24-
// SAFETY: we only call `init` once, namely here.
24+
// SAFETY: we only call `init` once per `pal::Mutex`, namely here.
2525
unsafe { pal.as_mut().init() };
2626
pal
2727
})

0 commit comments

Comments
 (0)