mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-112606: Use pthread_cond_timedwait_relative_np() in parking_lot.c when available (#112616)
Add a configure define for HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP and replaces pthread_cond_timedwait() with pthread_cond_timedwait_relative_np() for relative time when supported in semaphore waiting logic.
This commit is contained in:
parent
fda7445ca5
commit
e5e186609f
4 changed files with 17 additions and 3 deletions
|
@ -158,11 +158,15 @@ _PySemaphore_PlatformWait(_PySemaphore *sema, _PyTime_t timeout)
|
|||
if (sema->counter == 0) {
|
||||
if (timeout >= 0) {
|
||||
struct timespec ts;
|
||||
|
||||
#if defined(HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP)
|
||||
_PyTime_AsTimespec_clamp(timeout, &ts);
|
||||
err = pthread_cond_timedwait_relative_np(&sema->cond, &sema->mutex, &ts);
|
||||
#else
|
||||
_PyTime_t deadline = _PyTime_Add(_PyTime_GetSystemClock(), timeout);
|
||||
_PyTime_AsTimespec_clamp(deadline, &ts);
|
||||
|
||||
err = pthread_cond_timedwait(&sema->cond, &sema->mutex, &ts);
|
||||
#endif // HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
|
||||
}
|
||||
else {
|
||||
err = pthread_cond_wait(&sema->cond, &sema->mutex);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue