From ee1a1459126b4b65bd09acf0ba31b603c0032099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Fri, 21 Jan 2022 10:22:13 -0300 Subject: [PATCH] use clock_gettime instead of gettimeofday --- configure.ac | 2 +- src/cysignals/implementation.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index 03e26037..d0624ecd 100644 --- a/configure.ac +++ b/configure.ac @@ -27,7 +27,7 @@ CXX="$CC" CXXFLAGS="$CFLAGS" AC_PROG_CXX() -AC_CHECK_HEADERS([execinfo.h sys/mman.h sys/prctl.h sys/time.h sys/wait.h windows.h]) +AC_CHECK_HEADERS([execinfo.h sys/mman.h sys/prctl.h time.h sys/wait.h windows.h]) AC_CHECK_FUNCS([fork kill sigprocmask sigaltstack backtrace]) diff --git a/src/cysignals/implementation.c b/src/cysignals/implementation.c index 3551c2af..2afd6ad2 100644 --- a/src/cysignals/implementation.c +++ b/src/cysignals/implementation.c @@ -38,8 +38,8 @@ Interrupt and signal handling for Cython #if HAVE_SYS_TYPES_H #include #endif -#if HAVE_SYS_TIME_H -#include +#if HAVE_TIME_H +#include #endif #if HAVE_SYS_WAIT_H #include @@ -102,7 +102,7 @@ void custom_set_pending_signal(int sig){ #if ENABLE_DEBUG_CYSIGNALS -static struct timeval sigtime; /* Time of signal */ +static struct timespec sigtime; /* Time of signal */ #endif /* The cysigs object (there is a unique copy of this, shared by all @@ -289,7 +289,7 @@ static void cysigs_interrupt_handler(int sig) if (cysigs.debug_level >= 3) print_backtrace(); /* Store time of this signal, unless there is already a * pending signal. */ - if (!cysigs.interrupt_received) gettimeofday(&sigtime, NULL); + if (!cysigs.interrupt_received) clock_gettime(CLOCK_MONOTONIC, &sigtime); } #endif @@ -342,7 +342,7 @@ static void cysigs_signal_handler(int sig) print_stderr_long(sig); print_stderr(" *** inside sig_on\n"); if (cysigs.debug_level >= 3) print_backtrace(); - gettimeofday(&sigtime, NULL); + clock_gettime(CLOCK_MONOTONIC, &sigtime); } #endif @@ -452,10 +452,10 @@ static void setup_trampoline(void) static void do_raise_exception(int sig) { #if ENABLE_DEBUG_CYSIGNALS - struct timeval raisetime; + struct timespec raisetime; if (cysigs.debug_level >= 2) { - gettimeofday(&raisetime, NULL); - long delta_ms = (raisetime.tv_sec - sigtime.tv_sec)*1000L + ((long)raisetime.tv_usec - (long)sigtime.tv_usec)/1000; + clock_gettime(CLOCK_MONOTONIC, &raisetime); + long delta_ms = (raisetime.tv_sec - sigtime.tv_sec)*1000L + (raisetime.tv_nsec - sigtime.tv_nsec)/1000000L; PyGILState_STATE gilstate = PyGILState_Ensure(); print_stderr("do_raise_exception(sig="); print_stderr_long(sig);