>From 57c9f6a9dfd070fba31da73bfaa14769324be668 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 16 Sep 2018 09:02:15 -0700 Subject: [PATCH 1/2] Simplify by not worrying about setitimer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For a decade, POSIX has recommended that applications use timer_settime, not the obsolescent setitimer function. By now support for timer_settime is universal on POSIXish platforms, so it’s time to drop attempts to use setitimer. * configure.ac: Do not check for setitimer. * src/atimer.c (start_atimer, set_alarm) (debug_timer_callback): * src/profiler.c (setup_cpu_timer, Fprofiler_cpu_stop): * src/syssignal.h (PROFILER_CPU_SUPPORT): Simplify by not worrying about setitimer. * src/profiler.c (SETITIMER_RUNNING): Remove. All uses removed. --- admin/CPP-DEFINES | 1 - configure.ac | 2 +- src/atimer.c | 15 ++------------- src/profiler.c | 20 +------------------- src/syssignal.h | 3 +-- 5 files changed, 5 insertions(+), 36 deletions(-) diff --git a/admin/CPP-DEFINES b/admin/CPP-DEFINES index 04d1ff76f3..86a9a3c820 100644 --- a/admin/CPP-DEFINES +++ b/admin/CPP-DEFINES @@ -251,7 +251,6 @@ HAVE_RSVG HAVE_SELECT HAVE_SENDTO HAVE_SEQPACKET -HAVE_SETITIMER HAVE_SETLOCALE HAVE_SETRLIMIT HAVE_SHARED_GAME_DIR diff --git a/configure.ac b/configure.ac index 6f3d7338c3..9277f3789f 100644 --- a/configure.ac +++ b/configure.ac @@ -4013,7 +4013,7 @@ AC_DEFUN lrand48 random rint trunc \ select getpagesize setlocale newlocale \ getrlimit setrlimit shutdown \ -pthread_sigmask strsignal setitimer \ +pthread_sigmask strsignal \ sendto recvfrom getsockname getifaddrs freeifaddrs \ gai_strerror sync \ getpwent endpwent getgrent endgrent \ diff --git a/src/atimer.c b/src/atimer.c index 505f6bcea1..5848627d45 100644 --- a/src/atimer.c +++ b/src/atimer.c @@ -113,7 +113,7 @@ start_atimer (enum atimer_type type, struct timespec timestamp, sigset_t oldset; /* Round TIMESTAMP up to the next full second if we don't have itimers. */ -#if ! (defined HAVE_ITIMERSPEC || defined HAVE_SETITIMER) +#ifndef HAVE_ITIMERSPEC if (timestamp.tv_nsec != 0 && timestamp.tv_sec < TYPE_MAXIMUM (time_t)) timestamp = make_timespec (timestamp.tv_sec + 1, 0); #endif @@ -295,9 +295,6 @@ set_alarm (void) { if (atimers) { -#ifdef HAVE_SETITIMER - struct itimerval it; -#endif struct timespec now, interval; #ifdef HAVE_ITIMERSPEC @@ -325,15 +322,7 @@ set_alarm (void) interval = (timespec_cmp (atimers->expiration, now) <= 0 ? make_timespec (0, 1000 * 1000) : timespec_sub (atimers->expiration, now)); - -#ifdef HAVE_SETITIMER - - memset (&it, 0, sizeof it); - it.it_value = make_timeval (interval); - setitimer (ITIMER_REAL, &it, 0); -#else /* not HAVE_SETITIMER */ alarm (max (interval.tv_sec, 1)); -#endif /* not HAVE_SETITIMER */ } } @@ -495,7 +484,7 @@ debug_timer_callback (struct atimer *t) else if (result >= 0) { bool intime = true; -#if defined HAVE_ITIMERSPEC || defined HAVE_SETITIMER +#ifdef HAVE_ITIMERSPEC struct timespec delta = timespec_sub (now, r->expected); /* Too late if later than expected + 0.02s. FIXME: this should depend from system clock resolution. */ diff --git a/src/profiler.c b/src/profiler.c index 7330f8861f..23b82600f3 100644 --- a/src/profiler.c +++ b/src/profiler.c @@ -202,9 +202,8 @@ static bool profiler_timer_ok; static enum profiler_cpu_running { NOT_RUNNING, #ifdef HAVE_ITIMERSPEC - TIMER_SETTIME_RUNNING, + TIMER_SETTIME_RUNNING #endif - SETITIMER_RUNNING } profiler_cpu_running; @@ -262,7 +261,6 @@ static int setup_cpu_timer (Lisp_Object sampling_interval) { struct sigaction action; - struct itimerval timer; struct timespec interval; int billion = 1000000000; @@ -318,12 +316,6 @@ setup_cpu_timer (Lisp_Object sampling_interval) } #endif -#ifdef HAVE_SETITIMER - timer.it_value = timer.it_interval = make_timeval (interval); - if (setitimer (ITIMER_PROF, &timer, 0) == 0) - return SETITIMER_RUNNING; -#endif - return NOT_RUNNING; } @@ -380,16 +372,6 @@ Return non-nil if the profiler was running. */) } break; #endif - -#ifdef HAVE_SETITIMER - case SETITIMER_RUNNING: - { - struct itimerval disable; - memset (&disable, 0, sizeof disable); - setitimer (ITIMER_PROF, &disable, 0); - } - break; -#endif } signal (SIGPROF, SIG_IGN); diff --git a/src/syssignal.h b/src/syssignal.h index 0887eacb05..790413178e 100644 --- a/src/syssignal.h +++ b/src/syssignal.h @@ -47,8 +47,7 @@ extern void unblock_tty_out_signal (sigset_t const *); # define HAVE_ITIMERSPEC #endif -#if (defined SIGPROF && !defined PROFILING \ - && (defined HAVE_SETITIMER || defined HAVE_ITIMERSPEC)) +#if defined SIGPROF && !defined PROFILING && defined HAVE_ITIMERSPEC # define PROFILER_CPU_SUPPORT #endif -- 2.17.1