]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-112606: Use pthread_cond_timedwait_relative_np() in parking_lot.c when available...
authorMatt Prodani <mattp@nyu.edu>
Tue, 30 Jan 2024 21:22:17 +0000 (16:22 -0500)
committerGitHub <noreply@github.com>
Tue, 30 Jan 2024 21:22:17 +0000 (22:22 +0100)
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.

Python/parking_lot.c
configure
configure.ac
pyconfig.h.in

index d44c1b4b93b4d2b1140ad4371461c44b025ae320..c83d7443e289c56c4164f6b5fe1fe9265dccc0b0 100644 (file)
@@ -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);
index adc5a8f014c795a8acc49557716241f3a98e5f3e..7b2119ff7f4f78426ee7be61792baf3d47788db3 100755 (executable)
--- a/configure
+++ b/configure
@@ -17871,6 +17871,12 @@ if test "x$ac_cv_func_preadv2" = xyes
 then :
   printf "%s\n" "#define HAVE_PREADV2 1" >>confdefs.h
 
+fi
+ac_fn_c_check_func "$LINENO" "pthread_cond_timedwait_relative_np" "ac_cv_func_pthread_cond_timedwait_relative_np"
+if test "x$ac_cv_func_pthread_cond_timedwait_relative_np" = xyes
+then :
+  printf "%s\n" "#define HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP 1" >>confdefs.h
+
 fi
 ac_fn_c_check_func "$LINENO" "pthread_condattr_setclock" "ac_cv_func_pthread_condattr_setclock"
 if test "x$ac_cv_func_pthread_condattr_setclock" = xyes
index f5fa17fd8b7d0dccab7e88f76dfa0276850fd960..5bef2351c987e838e9b4dba0effce83f063ed8f5 100644 (file)
@@ -4796,8 +4796,8 @@ AC_CHECK_FUNCS([ \
   mknod mknodat mktime mmap mremap nice openat opendir pathconf pause pipe \
   pipe2 plock poll posix_fadvise posix_fallocate posix_openpt posix_spawn posix_spawnp \
   posix_spawn_file_actions_addclosefrom_np \
-  pread preadv preadv2 pthread_condattr_setclock pthread_init pthread_kill ptsname ptsname_r \
-  pwrite pwritev pwritev2 readlink readlinkat readv realpath renameat \
+  pread preadv preadv2 pthread_cond_timedwait_relative_np pthread_condattr_setclock pthread_init \
+  pthread_kill ptsname ptsname_r pwrite pwritev pwritev2 readlink readlinkat readv realpath renameat \
   rtpSpawn sched_get_priority_max sched_rr_get_interval sched_setaffinity \
   sched_setparam sched_setscheduler sem_clockwait sem_getvalue sem_open \
   sem_timedwait sem_unlink sendfile setegid seteuid setgid sethostname \
index 02e33c7007196d3dc7325b1a3083dc5634d02241..b22740710bcbee508d44d6354773f1b63d30ff55 100644 (file)
 /* Define to 1 if you have the `pthread_condattr_setclock' function. */
 #undef HAVE_PTHREAD_CONDATTR_SETCLOCK
 
+/* Define to 1 if you have the `pthread_cond_timedwait_relative_np' function.
+   */
+#undef HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
+
 /* Defined for Solaris 2.6 bug in pthread header. */
 #undef HAVE_PTHREAD_DESTRUCTOR