mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39: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 (sema->counter == 0) {
|
||||||
if (timeout >= 0) {
|
if (timeout >= 0) {
|
||||||
struct timespec ts;
|
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_t deadline = _PyTime_Add(_PyTime_GetSystemClock(), timeout);
|
||||||
_PyTime_AsTimespec_clamp(deadline, &ts);
|
_PyTime_AsTimespec_clamp(deadline, &ts);
|
||||||
|
|
||||||
err = pthread_cond_timedwait(&sema->cond, &sema->mutex, &ts);
|
err = pthread_cond_timedwait(&sema->cond, &sema->mutex, &ts);
|
||||||
|
#endif // HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
err = pthread_cond_wait(&sema->cond, &sema->mutex);
|
err = pthread_cond_wait(&sema->cond, &sema->mutex);
|
||||||
|
|
6
configure
generated
vendored
6
configure
generated
vendored
|
@ -17871,6 +17871,12 @@ if test "x$ac_cv_func_preadv2" = xyes
|
||||||
then :
|
then :
|
||||||
printf "%s\n" "#define HAVE_PREADV2 1" >>confdefs.h
|
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
|
fi
|
||||||
ac_fn_c_check_func "$LINENO" "pthread_condattr_setclock" "ac_cv_func_pthread_condattr_setclock"
|
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
|
if test "x$ac_cv_func_pthread_condattr_setclock" = xyes
|
||||||
|
|
|
@ -4796,8 +4796,8 @@ AC_CHECK_FUNCS([ \
|
||||||
mknod mknodat mktime mmap mremap nice openat opendir pathconf pause pipe \
|
mknod mknodat mktime mmap mremap nice openat opendir pathconf pause pipe \
|
||||||
pipe2 plock poll posix_fadvise posix_fallocate posix_openpt posix_spawn posix_spawnp \
|
pipe2 plock poll posix_fadvise posix_fallocate posix_openpt posix_spawn posix_spawnp \
|
||||||
posix_spawn_file_actions_addclosefrom_np \
|
posix_spawn_file_actions_addclosefrom_np \
|
||||||
pread preadv preadv2 pthread_condattr_setclock pthread_init pthread_kill ptsname ptsname_r \
|
pread preadv preadv2 pthread_cond_timedwait_relative_np pthread_condattr_setclock pthread_init \
|
||||||
pwrite pwritev pwritev2 readlink readlinkat readv realpath renameat \
|
pthread_kill ptsname ptsname_r pwrite pwritev pwritev2 readlink readlinkat readv realpath renameat \
|
||||||
rtpSpawn sched_get_priority_max sched_rr_get_interval sched_setaffinity \
|
rtpSpawn sched_get_priority_max sched_rr_get_interval sched_setaffinity \
|
||||||
sched_setparam sched_setscheduler sem_clockwait sem_getvalue sem_open \
|
sched_setparam sched_setscheduler sem_clockwait sem_getvalue sem_open \
|
||||||
sem_timedwait sem_unlink sendfile setegid seteuid setgid sethostname \
|
sem_timedwait sem_unlink sendfile setegid seteuid setgid sethostname \
|
||||||
|
|
|
@ -936,6 +936,10 @@
|
||||||
/* Define to 1 if you have the `pthread_condattr_setclock' function. */
|
/* Define to 1 if you have the `pthread_condattr_setclock' function. */
|
||||||
#undef HAVE_PTHREAD_CONDATTR_SETCLOCK
|
#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. */
|
/* Defined for Solaris 2.6 bug in pthread header. */
|
||||||
#undef HAVE_PTHREAD_DESTRUCTOR
|
#undef HAVE_PTHREAD_DESTRUCTOR
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue