summaryrefslogtreecommitdiffstats
path: root/Python/pytime.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-03-20 00:42:20 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-03-20 00:42:20 (GMT)
commit9a8089b32adee874caefbe2a96096998625c5a78 (patch)
treebf91050cbe41ad7811a975acc3bab8ed4ee97c02 /Python/pytime.c
parent4fa99cdb4c5f53d6fa86ef223ae613cb1a8783f8 (diff)
downloadcpython-9a8089b32adee874caefbe2a96096998625c5a78.zip
cpython-9a8089b32adee874caefbe2a96096998625c5a78.tar.gz
cpython-9a8089b32adee874caefbe2a96096998625c5a78.tar.bz2
Issue #23646: Enhance precision of time.sleep() and socket timeout when
interrupted by a signal Add a new _PyTime_AddDouble() function and remove _PyTime_ADD_SECONDS() macro. The _PyTime_ADD_SECONDS only supported an integer number of seconds, the _PyTime_AddDouble() has subsecond resolution.
Diffstat (limited to 'Python/pytime.c')
-rw-r--r--Python/pytime.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/Python/pytime.c b/Python/pytime.c
index cdaa22e..894008d 100644
--- a/Python/pytime.c
+++ b/Python/pytime.c
@@ -367,6 +367,23 @@ _PyTime_ObjectToTimeval(PyObject *obj, time_t *sec, long *usec,
return _PyTime_ObjectToDenominator(obj, sec, usec, 1e6, round);
}
+void
+_PyTime_AddDouble(_PyTime_timeval *tv, double interval, _PyTime_round_t round)
+{
+ _PyTime_timeval tv2;
+ double frac;
+
+ frac = fmod(interval, 1.0);
+ interval = floor(interval);
+ tv2.tv_sec = (long)interval;
+ tv2.tv_usec = (long)(frac*1e6);
+
+ tv->tv_sec += tv2.tv_sec;
+ tv->tv_usec += tv2.tv_usec;
+ tv->tv_sec += (time_t)(tv->tv_usec / 1000000);
+ tv->tv_usec %= 1000000;
+}
+
int
_PyTime_Init(void)
{