Skip to content

Commit b1f04a3

Browse files
author
Vitali Lovich
committed
Fix unit test compilation
Also fix some code snippets in documentation.
1 parent 6fe2d1d commit b1f04a3

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/libstd/sync/condvar.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ impl Condvar {
244244
/// # Examples
245245
///
246246
/// ```
247+
/// #![feature(wait_until)]
248+
///
247249
/// use std::sync::{Arc, Mutex, Condvar};
248250
/// use std::thread;
249251
///
@@ -261,7 +263,7 @@ impl Condvar {
261263
/// // Wait for the thread to start up.
262264
/// let &(ref lock, ref cvar) = &*pair;
263265
/// // As long as the value inside the `Mutex` is false, we wait.
264-
/// cvar.wait_until(lock.lock().unwrap(), |started| { started });
266+
/// let _guard = cvar.wait_until(lock.lock().unwrap(), |started| { *started }).unwrap();
265267
/// ```
266268
#[unstable(feature = "wait_until", issue = "47960")]
267269
pub fn wait_until<'a, T, F>(&self, mut guard: MutexGuard<'a, T>,
@@ -445,6 +447,8 @@ impl Condvar {
445447
/// # Examples
446448
///
447449
/// ```
450+
/// #![feature(wait_timeout_until)]
451+
///
448452
/// use std::sync::{Arc, Mutex, Condvar};
449453
/// use std::thread;
450454
/// use std::time::Duration;
@@ -462,8 +466,8 @@ impl Condvar {
462466
///
463467
/// // wait for the thread to start up
464468
/// let &(ref lock, ref cvar) = &*pair;
465-
/// let result = cvar.wait_timeout_until(lock, Duration::from_millis(100), |started| {
466-
/// started
469+
/// let result = cvar.wait_timeout_until(lock.lock().unwrap(), Duration::from_millis(100), |started| {
470+
/// *started
467471
/// }).unwrap();
468472
/// if result.1.timed_out() {
469473
/// // timed-out without the condition ever evaluating to true.
@@ -613,6 +617,7 @@ impl Drop for Condvar {
613617

614618
#[cfg(test)]
615619
mod tests {
620+
/// #![feature(wait_until)]
616621
use sync::mpsc::channel;
617622
use sync::{Condvar, Mutex, Arc};
618623
use sync::atomic::{AtomicBool, Ordering};
@@ -699,9 +704,9 @@ mod tests {
699704
// Wait for the thread to start up.
700705
let &(ref lock, ref cvar) = &*pair;
701706
let guard = cvar.wait_until(lock.lock().unwrap(), |started| {
702-
started
707+
*started
703708
});
704-
assert!(*guard);
709+
assert!(*guard.unwrap());
705710
}
706711

707712
#[test]
@@ -730,7 +735,7 @@ mod tests {
730735
let c = Arc::new(Condvar::new());
731736

732737
let g = m.lock().unwrap();
733-
let (_g, wait) = c.wait_timeout_until(g, Duration::from_millis(1), || { false }).unwrap();
738+
let (_g, wait) = c.wait_timeout_until(g, Duration::from_millis(1), |_| { false }).unwrap();
734739
// no spurious wakeups. ensure it timed-out
735740
assert!(wait.timed_out());
736741
}
@@ -742,7 +747,7 @@ mod tests {
742747
let c = Arc::new(Condvar::new());
743748

744749
let g = m.lock().unwrap();
745-
let (_g, wait) = c.wait_timeout_until(g, Duration::from_millis(0), || { true }).unwrap();
750+
let (_g, wait) = c.wait_timeout_until(g, Duration::from_millis(0), |_| { true }).unwrap();
746751
// ensure it didn't time-out even if we were not given any time.
747752
assert!(!wait.timed_out());
748753
}
@@ -753,15 +758,16 @@ mod tests {
753758
let pair = Arc::new((Mutex::new(false), Condvar::new()));
754759
let pair_copy = pair.clone();
755760

761+
let &(ref m, ref c) = &*pair;
756762
let g = m.lock().unwrap();
757-
let t = thread::spawn(move || {
758-
let &(ref lock, ref cvar) = &*pair2;
763+
let _t = thread::spawn(move || {
764+
let &(ref lock, ref cvar) = &*pair_copy;
759765
let mut started = lock.lock().unwrap();
760766
thread::sleep(Duration::from_millis(1));
761-
started = true;
767+
*started = true;
762768
cvar.notify_one();
763769
});
764-
let (g2, wait) = c.wait_timeout_until(g, Duration::from_millis(u64::MAX), |&notified| {
770+
let (g2, wait) = c.wait_timeout_until(g, Duration::from_millis(u64::MAX), |&mut notified| {
765771
notified
766772
}).unwrap();
767773
// ensure it didn't time-out even if we were not given any time.

0 commit comments

Comments
 (0)