@@ -220,8 +220,9 @@ impl Condvar {
220
220
}
221
221
222
222
/// 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.
225
226
///
226
227
/// This function will atomically unlock the mutex specified (represented by
227
228
/// `guard`) and block the current thread. This means that any calls
@@ -260,14 +261,14 @@ impl Condvar {
260
261
/// // Wait for the thread to start up.
261
262
/// let &(ref lock, ref cvar) = &*pair;
262
263
/// // 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 });
264
265
/// ```
265
266
#[ stable( feature = "wait_until" , since = "1.24" ) ]
266
267
pub fn wait_until < ' a , T , F > ( & self , mut guard : MutexGuard < ' a , T > ,
267
268
mut condition : F )
268
269
-> 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) {
271
272
guard = self . wait ( guard) ?;
272
273
}
273
274
Ok ( guard)
@@ -418,7 +419,8 @@ impl Condvar {
418
419
}
419
420
420
421
/// 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.
422
424
///
423
425
/// The semantics of this function are equivalent to [`wait_until`] except
424
426
/// that the thread will be blocked for roughly no longer than `dur`. This
@@ -472,10 +474,10 @@ impl Condvar {
472
474
pub fn wait_timeout_until < ' a , T , F > ( & self , mut guard : MutexGuard < ' a , T > ,
473
475
mut dur : Duration , mut condition : F )
474
476
-> LockResult < ( MutexGuard < ' a , T > , WaitTimeoutResult ) >
475
- where F : FnMut ( & T ) -> bool {
477
+ where F : FnMut ( & mut T ) -> bool {
476
478
let timed_out = Duration :: new ( 0 , 0 ) ;
477
479
loop {
478
- if !condition ( & * guard) {
480
+ if !condition ( & mut * guard) {
479
481
return Ok ( ( guard, WaitTimeoutResult ( false ) ) ) ;
480
482
} else if dur == timed_out {
481
483
return Ok ( ( guard, WaitTimeoutResult ( true ) ) ) ;
0 commit comments