Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-21302: Add clock_nanosleep() implementation for time.sleep() #28111

Merged
merged 45 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
55faeb6
clock_nanosleep() implementation for time.sleep()
Livius90 Sep 1, 2021
c7bae3b
Follow PEP 7 rules in time.sleep()
Livius90 Sep 1, 2021
b3a5c5f
Adjust braces to PEP 7
Livius90 Sep 1, 2021
3e07f39
clock_nanosleep check placed after clock_settime
Livius90 Sep 1, 2021
e06ba84
Fix EINTR issue for clock_nanosleep()
Livius90 Sep 1, 2021
6e6d4a3
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 1, 2021
238f073
nanosleep() is available for Unix systems like OSX, FreeBSD
Livius90 Sep 1, 2021
b5a5c6e
Update news rst file
Livius90 Sep 1, 2021
d064255
replace select() with nanosleep()
Livius90 Sep 2, 2021
b70f187
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 2, 2021
6ad7c14
Fix test_eintr issue for macOS
Livius90 Sep 2, 2021
74c45e1
Remove news rst and regenerate
Livius90 Sep 2, 2021
5988222
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 2, 2021
129b0a0
Use waitable timer from Win32 for time.sleep() in Windows
Livius90 Sep 3, 2021
d89e13b
Finalized waitable timer for time.sleep() in Windows
Livius90 Sep 3, 2021
47249f5
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 3, 2021
0bf8330
Fix macOS build issue
Livius90 Sep 3, 2021
085cbed
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 3, 2021
2242638
Final optimization in Waitable timer object implementation
Livius90 Sep 4, 2021
db7851b
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 4, 2021
f7387e8
revert to original
Livius90 Sep 9, 2021
a35b0b4
remove news
Livius90 Sep 9, 2021
3abf812
add clock_nanosleep() only
Livius90 Sep 9, 2021
4cbfde2
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 10, 2021
d99c06e
Update Misc/NEWS.d/next/Library/2021-09-10-00-24-08.bpo-21302.XS_frc.rst
Livius90 Sep 10, 2021
117dc62
timeout_abs renaming
Livius90 Sep 10, 2021
92061f3
Simplified HAVE_CLOCK_NANOSLEEP macro blocks
Livius90 Sep 10, 2021
f045047
remake news
Livius90 Sep 10, 2021
24f9975
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 10, 2021
34e3883
Fix err checking
Livius90 Sep 10, 2021
fec634f
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 10, 2021
8022062
revert changes
Livius90 Sep 10, 2021
4685ec7
get_monotonic() and secs re-calculation are useless for clock_nanosle…
Livius90 Sep 10, 2021
0ad19e0
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 10, 2021
0839d0d
merge errno in HAVE_CLOCK_NANOSLEEP
Livius90 Sep 11, 2021
39cff8f
remake news rst
Livius90 Sep 11, 2021
87d5712
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 11, 2021
56cb8e1
Try to fix Address sanitizer test issue
Livius90 Sep 11, 2021
8ec03be
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 11, 2021
b1ccdba
#2 Try to fix Address sanitizer test issue
Livius90 Sep 11, 2021
c8372c8
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 11, 2021
1cf2205
remake news rst
Livius90 Sep 11, 2021
1e725da
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 11, 2021
3566c59
re-make news rst
Livius90 Sep 11, 2021
278aaa2
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Modules/timemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2053,7 +2053,11 @@ pysleep(_PyTime_t secs)
{
_PyTime_t deadline, monotonic;
#ifndef MS_WINDOWS
#ifdef HAVE_CLOCK_NANOSLEEP
struct timespec timeout_abs;
#else
struct timeval timeout;
#endif
int err = 0;
#else
_PyTime_t millisecs;
Expand All @@ -2066,14 +2070,24 @@ pysleep(_PyTime_t secs)
return -1;
}
deadline = monotonic + secs;
#ifdef HAVE_CLOCK_NANOSLEEP
if (_PyTime_AsTimespec(deadline, &timeout_abs) < 0)
Livius90 marked this conversation as resolved.
Show resolved Hide resolved
return -1;
#endif

do {
#ifndef MS_WINDOWS
#ifndef HAVE_CLOCK_NANOSLEEP
if (_PyTime_AsTimeval(secs, &timeout, _PyTime_ROUND_CEILING) < 0)
return -1;
#endif

Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_CLOCK_NANOSLEEP
err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &timeout_abs, NULL);
#else
err = select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &timeout);
#endif
Py_END_ALLOW_THREADS

if (err == 0)
Expand Down
58 changes: 58 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -13237,6 +13237,64 @@ fi
done


for ac_func in clock_nanosleep
do :
ac_fn_c_check_func "$LINENO" "clock_nanosleep" "ac_cv_func_clock_nanosleep"
if test "x$ac_cv_func_clock_nanosleep" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_CLOCK_NANOSLEEP 1
_ACEOF

else

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_nanosleep in -lrt" >&5
$as_echo_n "checking for clock_nanosleep in -lrt... " >&6; }
if ${ac_cv_lib_rt_clock_nanosleep+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lrt $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */

/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char clock_nanosleep ();
int
main ()
{
return clock_nanosleep ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_rt_clock_nanosleep=yes
else
ac_cv_lib_rt_clock_nanosleep=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_clock_nanosleep" >&5
$as_echo "$ac_cv_lib_rt_clock_nanosleep" >&6; }
if test "x$ac_cv_lib_rt_clock_nanosleep" = xyes; then :

$as_echo "#define HAVE_CLOCK_NANOSLEEP 1" >>confdefs.h


fi


fi
done


for ac_func in clock_getres
do :
ac_fn_c_check_func "$LINENO" "clock_getres" "ac_cv_func_clock_getres"
Expand Down
6 changes: 6 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -4086,6 +4086,12 @@ AC_CHECK_FUNCS(clock_gettime, [], [
])
])

AC_CHECK_FUNCS(clock_nanosleep, [], [
AC_CHECK_LIB(rt, clock_nanosleep, [
AC_DEFINE(HAVE_CLOCK_NANOSLEEP, 1)
])
])
Livius90 marked this conversation as resolved.
Show resolved Hide resolved

AC_CHECK_FUNCS(clock_getres, [], [
AC_CHECK_LIB(rt, clock_getres, [
AC_DEFINE(HAVE_CLOCK_GETRES, 1)
Expand Down
3 changes: 3 additions & 0 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@
/* Define to 1 if you have the `clock' function. */
#undef HAVE_CLOCK

/* Define to 1 if you have the `clock_nanosleep' function. */
#undef HAVE_CLOCK_NANOSLEEP

/* Define to 1 if you have the `clock_getres' function. */
#undef HAVE_CLOCK_GETRES

Expand Down