summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMatt Prodani <mattp@nyu.edu>2024-01-30 21:22:17 (GMT)
committerGitHub <noreply@github.com>2024-01-30 21:22:17 (GMT)
commite5e186609fdd74bc53e8478da22b76440d996baa (patch)
treee9b59d9f6fe02ea4799f1c969467c95a7d749097 /Python
parentfda7445ca50b892955fc31bd72a3615fef1d70c6 (diff)
downloadcpython-e5e186609fdd74bc53e8478da22b76440d996baa.zip
cpython-e5e186609fdd74bc53e8478da22b76440d996baa.tar.gz
cpython-e5e186609fdd74bc53e8478da22b76440d996baa.tar.bz2
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.
Diffstat (limited to 'Python')
-rw-r--r--Python/parking_lot.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/Python/parking_lot.c b/Python/parking_lot.c
index d44c1b4..c83d744 100644
--- a/Python/parking_lot.c
+++ b/Python/parking_lot.c
@@ -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);