@@ -140,33 +140,43 @@ impl Condvar {
140140 /// Wait on this condition variable for a notification, timing out after a
141141 /// specified duration.
142142 ///
143- /// The semantics of this function are equivalent to `wait()` except that
144- /// the thread will be blocked for roughly no longer than `dur`. This method
145- /// should not be used for precise timing due to anomalies such as
146- /// preemption or platform differences that may not cause the maximum amount
147- /// of time waited to be precisely `dur`.
143+ /// The semantics of this function are equivalent to `wait()`
144+ /// except that the thread will be blocked for roughly no longer
145+ /// than `ms` milliseconds. This method should not be used for
146+ /// precise timing due to anomalies such as preemption or platform
147+ /// differences that may not cause the maximum amount of time
148+ /// waited to be precisely `ms`.
148149 ///
149- /// If the wait timed out, then `false` will be returned. Otherwise if a
150- /// notification was received then `true` will be returned .
150+ /// The returned boolean is `false` only if the timeout is known
151+ /// to have elapsed .
151152 ///
152153 /// Like `wait`, the lock specified will be re-acquired when this function
153154 /// returns, regardless of whether the timeout elapsed or not.
154- #[ unstable ( feature = "std_misc " ) ]
155- pub fn wait_timeout < ' a , T > ( & self , guard : MutexGuard < ' a , T > , dur : Duration )
156- -> LockResult < ( MutexGuard < ' a , T > , bool ) > {
155+ #[ stable ( feature = "rust1" , since = "1.0.0 ") ]
156+ pub fn wait_timeout_ms < ' a , T > ( & self , guard : MutexGuard < ' a , T > , ms : u32 )
157+ -> LockResult < ( MutexGuard < ' a , T > , bool ) > {
157158 unsafe {
158159 let me: & ' static Condvar = & * ( self as * const _ ) ;
159- me. inner . wait_timeout ( guard, dur )
160+ me. inner . wait_timeout_ms ( guard, ms )
160161 }
161162 }
162163
164+ /// Deprecated: use `wait_timeout_ms` instead.
165+ #[ unstable( feature = "std_misc" ) ]
166+ #[ deprecated( since = "1.0.0" , reason = "use wait_timeout_ms instead" ) ]
167+ pub fn wait_timeout < ' a , T > ( & self , guard : MutexGuard < ' a , T > , dur : Duration )
168+ -> LockResult < ( MutexGuard < ' a , T > , bool ) > {
169+ self . wait_timeout_ms ( guard, dur. num_milliseconds ( ) as u32 )
170+ }
171+
163172 /// Wait on this condition variable for a notification, timing out after a
164173 /// specified duration.
165174 ///
166175 /// The semantics of this function are equivalent to `wait_timeout` except
167176 /// that the implementation will repeatedly wait while the duration has not
168177 /// passed and the provided function returns `false`.
169- #[ unstable( feature = "std_misc" ) ]
178+ #[ unstable( feature = "wait_timeout_with" ,
179+ reason = "unsure if this API is broadly needed or what form it should take" ) ]
170180 pub fn wait_timeout_with < ' a , T , F > ( & self ,
171181 guard : MutexGuard < ' a , T > ,
172182 dur : Duration ,
@@ -235,12 +245,12 @@ impl StaticCondvar {
235245 /// See `Condvar::wait_timeout`.
236246 #[ unstable( feature = "std_misc" ,
237247 reason = "may be merged with Condvar in the future" ) ]
238- pub fn wait_timeout < ' a , T > ( & ' static self , guard : MutexGuard < ' a , T > , dur : Duration )
239- -> LockResult < ( MutexGuard < ' a , T > , bool ) > {
248+ pub fn wait_timeout_ms < ' a , T > ( & ' static self , guard : MutexGuard < ' a , T > , ms : u32 )
249+ -> LockResult < ( MutexGuard < ' a , T > , bool ) > {
240250 let ( poisoned, success) = unsafe {
241251 let lock = mutex:: guard_lock ( & guard) ;
242252 self . verify ( lock) ;
243- let success = self . inner . wait_timeout ( lock, dur ) ;
253+ let success = self . inner . wait_timeout ( lock, Duration :: milliseconds ( ms as i64 ) ) ;
244254 ( mutex:: guard_poison ( & guard) . get ( ) , success)
245255 } ;
246256 if poisoned {
@@ -275,7 +285,8 @@ impl StaticCondvar {
275285 let now = SteadyTime :: now ( ) ;
276286 let consumed = & now - & start;
277287 let guard = guard_result. unwrap_or_else ( |e| e. into_inner ( ) ) ;
278- let ( new_guard_result, no_timeout) = match self . wait_timeout ( guard, dur - consumed) {
288+ let res = self . wait_timeout_ms ( guard, ( dur - consumed) . num_milliseconds ( ) as u32 ) ;
289+ let ( new_guard_result, no_timeout) = match res {
279290 Ok ( ( new_guard, no_timeout) ) => ( Ok ( new_guard) , no_timeout) ,
280291 Err ( err) => {
281292 let ( new_guard, no_timeout) = err. into_inner ( ) ;
@@ -350,6 +361,7 @@ mod tests {
350361 use sync:: atomic:: { AtomicUsize , ATOMIC_USIZE_INIT , Ordering } ;
351362 use thread;
352363 use time:: Duration ;
364+ use u32;
353365
354366 #[ test]
355367 fn smoke ( ) {
@@ -418,19 +430,19 @@ mod tests {
418430 }
419431
420432 #[ test]
421- fn wait_timeout ( ) {
433+ fn wait_timeout_ms ( ) {
422434 static C : StaticCondvar = CONDVAR_INIT ;
423435 static M : StaticMutex = MUTEX_INIT ;
424436
425437 let g = M . lock ( ) . unwrap ( ) ;
426- let ( g, _no_timeout) = C . wait_timeout ( g, Duration :: nanoseconds ( 1000 ) ) . unwrap ( ) ;
438+ let ( g, _no_timeout) = C . wait_timeout_ms ( g, 1 ) . unwrap ( ) ;
427439 // spurious wakeups mean this isn't necessarily true
428440 // assert!(!no_timeout);
429441 let _t = thread:: spawn ( move || {
430442 let _g = M . lock ( ) . unwrap ( ) ;
431443 C . notify_one ( ) ;
432444 } ) ;
433- let ( g, no_timeout) = C . wait_timeout ( g, Duration :: days ( 1 ) ) . unwrap ( ) ;
445+ let ( g, no_timeout) = C . wait_timeout_ms ( g, u32 :: MAX ) . unwrap ( ) ;
434446 assert ! ( no_timeout) ;
435447 drop ( g) ;
436448 unsafe { C . destroy ( ) ; M . destroy ( ) ; }
0 commit comments