Skip to content

Commit a2c8171

Browse files
committed
use clock_gettime instead of gettimeofday
1 parent 178bc95 commit a2c8171

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ CXX="$CC"
2727
CXXFLAGS="$CFLAGS"
2828
AC_PROG_CXX()
2929

30-
AC_CHECK_HEADERS([execinfo.h sys/mman.h sys/prctl.h sys/time.h sys/wait.h windows.h])
30+
AC_CHECK_HEADERS([execinfo.h sys/mman.h sys/prctl.h time.h sys/wait.h windows.h])
3131
AC_CHECK_FUNCS([fork kill sigprocmask sigaltstack backtrace])
3232

3333

src/cysignals/implementation.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ Interrupt and signal handling for Cython
3838
#if HAVE_SYS_TYPES_H
3939
#include <sys/types.h>
4040
#endif
41-
#if HAVE_SYS_TIME_H
42-
#include <sys/time.h>
41+
#if HAVE_TIME_H
42+
#include <time.h>
4343
#endif
4444
#if HAVE_SYS_WAIT_H
4545
#include <sys/wait.h>
@@ -71,7 +71,7 @@ static int PARI_SIGINT_pending = 0;
7171

7272

7373
#if ENABLE_DEBUG_CYSIGNALS
74-
static struct timeval sigtime; /* Time of signal */
74+
static struct timespec sigtime; /* Time of signal */
7575
#endif
7676

7777
/* The cysigs object (there is a unique copy of this, shared by all
@@ -258,7 +258,7 @@ static void cysigs_interrupt_handler(int sig)
258258
if (cysigs.debug_level >= 3) print_backtrace();
259259
/* Store time of this signal, unless there is already a
260260
* pending signal. */
261-
if (!cysigs.interrupt_received) gettimeofday(&sigtime, NULL);
261+
if (!cysigs.interrupt_received) clock_gettime(CLOCK_MONOTONIC, &sigtime);
262262
}
263263
#endif
264264

@@ -310,7 +310,7 @@ static void cysigs_signal_handler(int sig)
310310
print_stderr_long(sig);
311311
print_stderr(" *** inside sig_on\n");
312312
if (cysigs.debug_level >= 3) print_backtrace();
313-
gettimeofday(&sigtime, NULL);
313+
clock_gettime(CLOCK_MONOTONIC, &sigtime);
314314
}
315315
#endif
316316

@@ -420,10 +420,10 @@ static void setup_trampoline(void)
420420
static void do_raise_exception(int sig)
421421
{
422422
#if ENABLE_DEBUG_CYSIGNALS
423-
struct timeval raisetime;
423+
struct timespec raisetime;
424424
if (cysigs.debug_level >= 2) {
425-
gettimeofday(&raisetime, NULL);
426-
long delta_ms = (raisetime.tv_sec - sigtime.tv_sec)*1000L + ((long)raisetime.tv_usec - (long)sigtime.tv_usec)/1000;
425+
clock_gettime(CLOCK_MONOTONIC, &raisetime);
426+
long delta_ms = (raisetime.tv_sec - sigtime.tv_sec)*1000L + (raisetime.tv_nsec - sigtime.tv_nsec)/1000000L;
427427
PyGILState_STATE gilstate = PyGILState_Ensure();
428428
print_stderr("do_raise_exception(sig=");
429429
print_stderr_long(sig);

0 commit comments

Comments
 (0)