Skip to content

Commit

Permalink
use clock_gettime instead of gettimeofday
Browse files Browse the repository at this point in the history
  • Loading branch information
tornaria authored and Matthias Koeppe committed Sep 21, 2023
1 parent 9fb2e16 commit ee71143
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])


Expand Down
16 changes: 8 additions & 8 deletions src/cysignals/implementation.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ Interrupt and signal handling for Cython
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#if HAVE_TIME_H
#include <time.h>
#endif
#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
Expand Down Expand Up @@ -71,7 +71,7 @@ static int PARI_SIGINT_pending = 0;


#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
Expand Down Expand Up @@ -258,7 +258,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

Expand Down Expand Up @@ -310,7 +310,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

Expand Down Expand Up @@ -420,10 +420,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);
Expand Down

0 comments on commit ee71143

Please sign in to comment.