Skip to content

Commit e72bd6d

Browse files
author
Vitali Lovich
committed
Review response
Make condition closure accept mut T&. Clarify spurious wakeup documentation. Cleanup doc example code.
1 parent 404e1a6 commit e72bd6d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/libstd/sync/condvar.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,9 @@ impl Condvar {
220220
}
221221

222222
/// Blocks the current thread until this condition variable receives a
223-
/// notification and the required condition is met. There are no spurious
224-
/// wakeups when calling this.
223+
/// notification and the required condition is met. Spurious wakeups are
224+
/// ignored and this function will only return once the condition has been
225+
/// met.
225226
///
226227
/// This function will atomically unlock the mutex specified (represented by
227228
/// `guard`) and block the current thread. This means that any calls
@@ -260,14 +261,14 @@ impl Condvar {
260261
/// // Wait for the thread to start up.
261262
/// let &(ref lock, ref cvar) = &*pair;
262263
/// // As long as the value inside the `Mutex` is false, we wait.
263-
/// cvar.wait_until(lock.lock().unwrap(), |ref started| { started });
264+
/// cvar.wait_until(lock.lock().unwrap(), |started| { started });
264265
/// ```
265266
#[stable(feature = "wait_until", since = "1.24")]
266267
pub fn wait_until<'a, T, F>(&self, mut guard: MutexGuard<'a, T>,
267268
mut condition: F)
268269
-> LockResult<MutexGuard<'a, T>>
269-
where F: FnMut(&T) -> bool {
270-
while !condition(&*guard) {
270+
where F: FnMut(&mut T) -> bool {
271+
while !condition(&mut *guard) {
271272
guard = self.wait(guard)?;
272273
}
273274
Ok(guard)
@@ -418,7 +419,8 @@ impl Condvar {
418419
}
419420

420421
/// Waits on this condition variable for a notification, timing out after a
421-
/// specified duration.
422+
/// specified duration. Spurious wakes will not cause this function to
423+
/// return.
422424
///
423425
/// The semantics of this function are equivalent to [`wait_until`] except
424426
/// that the thread will be blocked for roughly no longer than `dur`. This
@@ -472,10 +474,10 @@ impl Condvar {
472474
pub fn wait_timeout_until<'a, T, F>(&self, mut guard: MutexGuard<'a, T>,
473475
mut dur: Duration, mut condition: F)
474476
-> LockResult<(MutexGuard<'a, T>, WaitTimeoutResult)>
475-
where F: FnMut(&T) -> bool {
477+
where F: FnMut(&mut T) -> bool {
476478
let timed_out = Duration::new(0, 0);
477479
loop {
478-
if !condition(&*guard) {
480+
if !condition(&mut *guard) {
479481
return Ok((guard, WaitTimeoutResult(false)));
480482
} else if dur == timed_out {
481483
return Ok((guard, WaitTimeoutResult(true)));

0 commit comments

Comments
 (0)