From 3da1891778735b0d24254f0f7a577c7b0e57c114 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Wed, 27 Jan 2021 15:26:19 +0100 Subject: [PATCH] merged signal.c in timer.c --- Makefile | 2 +- signal.c | 58 -------------------------------------------------------- timer.c | 1 + 3 files changed, 2 insertions(+), 59 deletions(-) delete mode 100644 signal.c diff --git a/Makefile b/Makefile index c6f3ff2..7b79248 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ TIME := \time -f "\ttime: %E real, %U user, %S sys\n\tcontext-switch:\t%c+%w, pa export PATH := .:$(PATH) TARGETS=lceb tree oper timer -OBJS=lceb.o tree.o oper.o stack.o eval.o best.o timer.o stack.o signal.o +OBJS=lceb.o tree.o oper.o stack.o eval.o best.o timer.o stack.o INCLUDES=lceb.h DEPS=$(INCLUDES) Makefile diff --git a/signal.c b/signal.c deleted file mode 100644 index 24af9f7..0000000 --- a/signal.c +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include -#include -#include -#include "lceb.h" - -int sigint_received=0; - -static void stopall(signum) - int signum; -{ - printf("SIGNAL %d RECEIVED: aborting eval\n", signum); - sigint_received=1; -} - -int stopped() -{ - return sigint_received; -} - -void set_intr() -{ - struct sigaction sig; - - sig.sa_handler = stopall; - sigemptyset(&sig.sa_mask); - sig.sa_flags = 0; - sigaction(SIGINT, &sig, NULL); - sigaction(SIGALRM, &sig, NULL); -# ifdef DEBUG - printf("SIGINT armed.\n"); -# endif -} - -void set_alarm(ms) - int ms; -{ - struct sigaction sa; - struct itimerval timer; - - /* Install timer_handler as the signal handler for SIGVTALRM. */ - memset (&sa, 0, sizeof (sa)); - sa.sa_handler = stopall; - sigaction (SIGUSR1, &sa, NULL); - - timer.it_value.tv_sec = ms/1000; - timer.it_value.tv_usec = (ms%1000)*1000; -# ifdef DEBUG - printf("alarm clock set to %.2f secs.\n", - timer.it_value.tv_sec + timer.it_value.tv_usec / 1000000.); -# endif - /* ... and every 250 msec after that. */ - timer.it_interval.tv_sec = 0; - timer.it_interval.tv_usec = 0; - /* Start a virtual timer. It counts down whenever this process is executing. */ - setitimer (ITIMER_REAL, &timer, NULL); - -} diff --git a/timer.c b/timer.c index 2749c68..1945e4c 100644 --- a/timer.c +++ b/timer.c @@ -29,6 +29,7 @@ double get_timer(timer) struct timespec timer; { double diff; + diff=(timer.tv_sec - start.tv_sec) + (timer.tv_nsec - start.tv_nsec) / NANOSEC; # ifdef DEBUG_TIMER printf("timer sec: %.5f\n", diff);