@@ -156,23 +156,23 @@ _PyThread_cond_init(PyCOND_T *cond)
156
156
return pthread_cond_init (cond , condattr_monotonic );
157
157
}
158
158
159
+
159
160
void
160
161
_PyThread_cond_after (long long us , struct timespec * abs )
161
162
{
163
+ _PyTime_t timeout = _PyTime_FromMicrosecondsClamp (us );
164
+ _PyTime_t t ;
162
165
#ifdef CONDATTR_MONOTONIC
163
166
if (condattr_monotonic ) {
164
- clock_gettime (CLOCK_MONOTONIC , abs );
165
- abs -> tv_sec += us / 1000000 ;
166
- abs -> tv_nsec += (us % 1000000 ) * 1000 ;
167
- abs -> tv_sec += abs -> tv_nsec / 1000000000 ;
168
- abs -> tv_nsec %= 1000000000 ;
169
- return ;
167
+ t = _PyTime_GetMonotonicClock ();
170
168
}
169
+ else
171
170
#endif
172
-
173
- struct timespec ts ;
174
- MICROSECONDS_TO_TIMESPEC (us , ts );
175
- * abs = ts ;
171
+ {
172
+ t = _PyTime_GetSystemClock ();
173
+ }
174
+ t = _PyTime_Add (t , timeout );
175
+ _PyTime_AsTimespec_clamp (t , abs );
176
176
}
177
177
178
178
@@ -639,17 +639,17 @@ PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds,
639
639
goto unlock ;
640
640
}
641
641
642
- struct timespec abs ;
642
+ struct timespec abs_timeout ;
643
643
if (microseconds > 0 ) {
644
- _PyThread_cond_after (microseconds , & abs );
644
+ _PyThread_cond_after (microseconds , & abs_timeout );
645
645
}
646
646
// Continue trying until we get the lock
647
647
648
648
// mut must be locked by me -- part of the condition protocol
649
649
while (1 ) {
650
650
if (microseconds > 0 ) {
651
651
status = pthread_cond_timedwait (& thelock -> lock_released ,
652
- & thelock -> mut , & abs );
652
+ & thelock -> mut , & abs_timeout );
653
653
if (status == 1 ) {
654
654
break ;
655
655
}
0 commit comments