@@ -219,34 +219,6 @@ impl Condvar {
219
219
self . wait_until_internal ( mutex, None ) ;
220
220
}
221
221
222
- /// Waits on this condition variable for a notification, timing out after
223
- /// the specified time instant.
224
- ///
225
- /// The semantics of this function are equivalent to `wait()` except that
226
- /// the thread will be blocked roughly until `timeout` is reached. This
227
- /// method should not be used for precise timing due to anomalies such as
228
- /// preemption or platform differences that may not cause the maximum
229
- /// amount of time waited to be precisely `timeout`.
230
- ///
231
- /// Note that the best effort is made to ensure that the time waited is
232
- /// measured with a monotonic clock, and not affected by the changes made to
233
- /// the system time.
234
- ///
235
- /// The returned `WaitTimeoutResult` value indicates if the timeout is
236
- /// known to have elapsed.
237
- ///
238
- /// Like `wait`, the lock specified will be re-acquired when this function
239
- /// returns, regardless of whether the timeout elapsed or not.
240
- ///
241
- /// # Panics
242
- ///
243
- /// This function will panic if another thread is waiting on the `Condvar`
244
- /// with a different `Mutex` object.
245
- #[ inline]
246
- pub fn wait_until ( & self , mutex : & RawMutex , timeout : Instant ) -> WaitTimeoutResult {
247
- self . wait_until_internal ( mutex, Some ( timeout) )
248
- }
249
-
250
222
// This is a non-generic function to reduce the monomorphization cost of
251
223
// using `wait_until`.
252
224
fn wait_until_internal ( & self , mutex : & RawMutex , timeout : Option < Instant > ) -> WaitTimeoutResult {
@@ -333,7 +305,14 @@ impl Condvar {
333
305
/// returns, regardless of whether the timeout elapsed or not.
334
306
#[ inline]
335
307
pub fn wait_for ( & self , mutex : & RawMutex , timeout : Duration ) -> WaitTimeoutResult {
336
- self . wait_until ( mutex, Instant :: now ( ) + timeout)
308
+ /// FIXME: As soon as `Instant::checked_add` is merged, use that instead.
309
+ const MAX_WAIT : Duration = Duration :: from_nanos ( u64:: max_value ( ) ) ;
310
+ let timeout = if timeout > MAX_WAIT {
311
+ None
312
+ } else {
313
+ Some ( Instant :: now ( ) + timeout)
314
+ } ;
315
+ self . wait_until_internal ( mutex, timeout)
337
316
}
338
317
}
339
318
@@ -355,7 +334,7 @@ mod tests {
355
334
use sync:: mpsc:: channel;
356
335
use sync:: Arc ;
357
336
use thread;
358
- use time:: { Duration , Instant } ;
337
+ use time:: Duration ;
359
338
use super :: { Condvar , RawMutex } ;
360
339
361
340
#[ test]
@@ -431,29 +410,6 @@ mod tests {
431
410
m. unlock ( ) ;
432
411
}
433
412
434
- #[ test]
435
- fn wait_until ( ) {
436
- let m = Arc :: new ( RawMutex :: INIT ) ;
437
- let m2 = m. clone ( ) ;
438
- let c = Arc :: new ( Condvar :: new ( ) ) ;
439
- let c2 = c. clone ( ) ;
440
-
441
- m. lock ( ) ;
442
- let no_timeout = c. wait_until ( & m, Instant :: now ( ) + Duration :: from_millis ( 1 ) ) ;
443
- assert ! ( no_timeout. timed_out( ) ) ;
444
- let _t = thread:: spawn ( move || {
445
- m2. lock ( ) ;
446
- c2. notify_one ( ) ;
447
- m2. unlock ( ) ;
448
- } ) ;
449
- let timeout_res = c. wait_until (
450
- & m,
451
- Instant :: now ( ) + Duration :: from_millis ( u32:: max_value ( ) as u64 ) ,
452
- ) ;
453
- assert ! ( !timeout_res. timed_out( ) ) ;
454
- m. unlock ( ) ;
455
- }
456
-
457
413
#[ test]
458
414
#[ should_panic]
459
415
fn two_mutexes ( ) {
0 commit comments