@@ -60,6 +60,14 @@ impl<I: PthreadCondTimedwaitSyscall> PthreadCondTimedwaitSyscall
6060 lock : * mut pthread_mutex_t ,
6161 abstime : * const timespec ,
6262 ) -> c_int {
63+ fn wait_time ( left_time : u64 ) -> u64 {
64+ if left_time > 10_000_000 {
65+ 10_000_000
66+ } else {
67+ left_time
68+ }
69+ }
70+
6371 #[ cfg( all( unix, feature = "preemptive" ) ) ]
6472 if crate :: monitor:: Monitor :: current ( ) . is_some ( ) {
6573 return self . inner . pthread_cond_timedwait (
@@ -87,13 +95,14 @@ impl<I: PthreadCondTimedwaitSyscall> PthreadCondTimedwaitSyscall
8795 if 0 == left_time {
8896 return libc:: ETIMEDOUT ;
8997 }
98+ let next_timeout = now ( ) . saturating_add ( wait_time ( left_time) ) ;
9099 let r = self . inner . pthread_cond_timedwait (
91100 fn_ptr,
92101 cond,
93102 lock,
94103 & timespec {
95- tv_sec : now ( ) . saturating_div ( 1_000_000_000 ) . saturating_add ( 1 ) . try_into ( ) . expect ( "overflow" ) ,
96- tv_nsec : 0 ,
104+ tv_sec : next_timeout . saturating_div ( 1_000_000_000 ) . try_into ( ) . expect ( "overflow" ) ,
105+ tv_nsec : next_timeout . wrapping_rem ( 1_000_000_000 ) . try_into ( ) . expect ( "overflow" ) ,
97106 } ,
98107 ) ;
99108 if libc:: ETIMEDOUT != r {
@@ -103,14 +112,10 @@ impl<I: PthreadCondTimedwaitSyscall> PthreadCondTimedwaitSyscall
103112 if 0 == left_time {
104113 return libc:: ETIMEDOUT ;
105114 }
106- let wait_time = if left_time > 10_000_000 {
107- 10_000_000
108- } else {
109- left_time
110- } ;
115+ let wait_time = wait_time ( left_time) ;
111116 if EventLoops :: wait_event ( Some ( Duration :: new (
112117 wait_time / 1_000_000_000 ,
113- ( wait_time % 1_000_000_000 ) as _ ,
118+ wait_time. wrapping_rem ( 1_000_000_000 ) . try_into ( ) . expect ( "overflow" ) ,
114119 ) ) )
115120 . is_err ( )
116121 {
0 commit comments