@@ -4010,7 +4010,7 @@ bool needs_forced_monotonic_fix(char *function_name)
40104010
40114011int pthread_cond_timedwait_common (pthread_cond_t * cond , pthread_mutex_t * mutex , const struct timespec * abstime , ft_lib_compat_pthread compat )
40124012{
4013- struct timespec tp , tdiff_actual , realtime , faketime ;
4013+ struct timespec tp , tdiff_actual , realtime , faketime , current_monotonic ;
40144014 struct timespec * tf = NULL ;
40154015 struct pthread_cond_monotonic * e ;
40164016 char * tmp_env ;
@@ -4060,7 +4060,12 @@ int pthread_cond_timedwait_common(pthread_cond_t *cond, pthread_mutex_t *mutex,
40604060 {
40614061 if (!fake_monotonic_clock && clk_id == CLOCK_MONOTONIC )
40624062 {
4063- timespecsub (abstime , & realtime , & tp );
4063+ DONT_FAKE_TIME (result = (* real_clock_gettime )(CLOCK_MONOTONIC , & current_monotonic ));
4064+ if (result == -1 )
4065+ {
4066+ return -1 ;
4067+ }
4068+ timespecsub (abstime , & current_monotonic , & tp );
40644069 }
40654070 else
40664071 {
@@ -4084,7 +4089,16 @@ int pthread_cond_timedwait_common(pthread_cond_t *cond, pthread_mutex_t *mutex,
40844089#ifndef __ARM_ARCH
40854090#ifndef FORCE_MONOTONIC_FIX
40864091 if (clk_id == CLOCK_MONOTONIC ) {
4087- if (needs_forced_monotonic_fix ("pthread_cond_timedwait" ) == true) {
4092+ if (!fake_monotonic_clock ) {
4093+ /* When not faking monotonic clock, use real monotonic time as base */
4094+ DONT_FAKE_TIME (result = (* real_clock_gettime )(CLOCK_MONOTONIC , & current_monotonic ));
4095+ if (result == -1 )
4096+ {
4097+ return -1 ;
4098+ }
4099+ timespecadd (& current_monotonic , & tdiff_actual , & tp );
4100+ }
4101+ else if (needs_forced_monotonic_fix ("pthread_cond_timedwait" ) == true) {
40884102 timespecadd (& realtime , & tdiff_actual , & tp );
40894103 }
40904104 else {
0 commit comments