diff options
author | Matt Prodani <mattp@nyu.edu> | 2023-12-06 06:54:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-06 06:54:57 (GMT) |
commit | a2a46f9f1e08be26fa1f732a2b92e355ad812abf (patch) | |
tree | a4ae690a733a7bb34a79a0c5c33403482500840a /Python | |
parent | d384813ff18b33280a90b6d2011654528a2b6ad1 (diff) | |
download | cpython-a2a46f9f1e08be26fa1f732a2b92e355ad812abf.zip cpython-a2a46f9f1e08be26fa1f732a2b92e355ad812abf.tar.gz cpython-a2a46f9f1e08be26fa1f732a2b92e355ad812abf.tar.bz2 |
gh-112606: Use sem_clockwait with monotonic time when supported in parking_lot.c (gh-112733)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/parking_lot.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Python/parking_lot.c b/Python/parking_lot.c index 664e622..d44c1b4 100644 --- a/Python/parking_lot.c +++ b/Python/parking_lot.c @@ -118,10 +118,19 @@ _PySemaphore_PlatformWait(_PySemaphore *sema, _PyTime_t timeout) if (timeout >= 0) { struct timespec ts; +#if defined(CLOCK_MONOTONIC) && defined(HAVE_SEM_CLOCKWAIT) + _PyTime_t deadline = _PyTime_Add(_PyTime_GetMonotonicClock(), timeout); + + _PyTime_AsTimespec_clamp(deadline, &ts); + + err = sem_clockwait(&sema->platform_sem, CLOCK_MONOTONIC, &ts); +#else _PyTime_t deadline = _PyTime_Add(_PyTime_GetSystemClock(), timeout); - _PyTime_AsTimespec(deadline, &ts); + + _PyTime_AsTimespec_clamp(deadline, &ts); err = sem_timedwait(&sema->platform_sem, &ts); +#endif } else { err = sem_wait(&sema->platform_sem); @@ -151,7 +160,7 @@ _PySemaphore_PlatformWait(_PySemaphore *sema, _PyTime_t timeout) struct timespec ts; _PyTime_t deadline = _PyTime_Add(_PyTime_GetSystemClock(), timeout); - _PyTime_AsTimespec(deadline, &ts); + _PyTime_AsTimespec_clamp(deadline, &ts); err = pthread_cond_timedwait(&sema->cond, &sema->mutex, &ts); } |