From e3e86227de314c06fd79f00cae61e01a73f2f111 Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Thu, 21 Jan 2016 19:52:40 +0100 Subject: [PATCH] Replace CENV_SYSF_BSDTIMEVAL with HAVE_SETITIMER and HAVE_GETTIMEOFDAY --- configure.ac | 3 ++- src/cenv.h | 3 --- src/dpsup.c | 2 +- src/kn10cpu.c | 4 ++-- src/osdsup.c | 22 +++++++++++----------- src/osdsup.h | 10 ++++++++-- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/configure.ac b/configure.ac index 19b68aa..0238507 100644 --- a/configure.ac +++ b/configure.ac @@ -69,7 +69,8 @@ AC_FUNC_MALLOC AC_FUNC_REALLOC AC_CHECK_FUNCS([alarm dup2 gettimeofday localtime_r memset socket strcasecmp \ strchr strcspn strerror strncasecmp strpbrk strrchr strtol \ - getifaddrs if_nameindex termios sigsetops sigaction nanosleep]) + getifaddrs if_nameindex termios sigsetops sigaction nanosleep \ + gettimeofday getrusage setitimer]) # Check for CPU. # This requires install-sh, config.sub, config.guess from automake. diff --git a/src/cenv.h b/src/cenv.h index 7dfa919..3bda1e2 100644 --- a/src/cenv.h +++ b/src/cenv.h @@ -215,9 +215,6 @@ /* Specific OS Feature defs This only has features of interest for KLH10 software. */ -#ifndef CENV_SYSF_BSDTIMEVAL /* Has "timeval" struct & calls */ -# define CENV_SYSF_BSDTIMEVAL (CENV_SYS_UNIX && !CENV_SYS_V7) -#endif #ifndef CENV_SYSF_TERMIOS /* Has termios(3) tty stuff */ # define CENV_SYSF_TERMIOS (CENV_SYS_DECOSF|CENV_SYS_SOLARIS|CENV_SYS_XBSD \ |CENV_SYS_LINUX) diff --git a/src/dpsup.c b/src/dpsup.c index cdd3bac..f6dc871 100644 --- a/src/dpsup.c +++ b/src/dpsup.c @@ -730,7 +730,7 @@ dp_sleep(int secs) #if CENV_SYS_DECOSF sleep(secs); /* Independent of interval timers! */ -#elif CENV_SYSF_BSDTIMEVAL && CENV_SYSF_SIGSET +#elif HAVE_SETITIMER && CENV_SYSF_SIGSET /* Must save & restore ITIMER_REAL & SIGALRM, which conflict w/sleep() */ struct itimerval ztm, otm; struct sigaction act, oact; diff --git a/src/kn10cpu.c b/src/kn10cpu.c index 8abd088..2ac3a61 100644 --- a/src/kn10cpu.c +++ b/src/kn10cpu.c @@ -1386,7 +1386,7 @@ quant_freeze(int32 qc) ** don't report runtime in a monotonically increasing way. ** See os_vrtmget() for more detail. */ -#if CENV_SYSF_BSDTIMEVAL +#if HAVE_SETITIMER if (rtm.tv_sec < 0 || rtm.tv_usec < 0) { # if 0 /* Disable output for now. Perhaps bump a meter later */ fprintf(stderr, "[Neg quantum! %ld,%ld]\r\n", @@ -1394,7 +1394,7 @@ quant_freeze(int32 qc) # endif return qc; } -#endif /* CENV_SYSF_BSDTIMEVAL */ +#endif /* HAVE_SETITIMER */ return qc + (int32)os_rtm_toqct(&rtm); /* Convert to quantum ticks! */ } diff --git a/src/osdsup.c b/src/osdsup.c index 192d683..b0d4ffe 100644 --- a/src/osdsup.c +++ b/src/osdsup.c @@ -65,7 +65,7 @@ # include # include /* For struct tm, localtime() */ -# if CENV_SYSF_BSDTIMEVAL +# if HAVE_SETITIMER # include /* BSD: For setitimer() */ # include /* BSD: For getrusage() */ # endif @@ -909,7 +909,7 @@ and fits within 20 bits. int os_rtmget(register osrtm_t *art) { -#if CENV_SYSF_BSDTIMEVAL +#if HAVE_SETITIMER /* && HAVE_GETTIMEOFDAY ; implied */ static osrtm_t os_last_rtm = {0,0}; if (!gettimeofday(art, (struct timezone *)NULL) == 0) return FALSE; @@ -949,7 +949,7 @@ os_vrtmget(register osrtm_t *art) return TRUE; } return FALSE; -#elif CENV_SYSF_BSDTIMEVAL +#elif HAVE_GETRUSAGE /* WARNING!!! Some systems turn out not to report getrusage runtime in a ** monotonically increasing way! This can result in negative deltas ** from one get to the next. @@ -978,7 +978,7 @@ os_vrtmget(register osrtm_t *art) void os_rtmsub(register osrtm_t *a, register osrtm_t *b) { -#if CENV_SYSF_BSDTIMEVAL +#if HAVE_SETITIMER a->tv_sec -= b->tv_sec; if ((a->tv_usec -= b->tv_usec) < 0) { --a->tv_sec; @@ -1062,7 +1062,7 @@ os_timer(int type, register uint32 usecs, ostimer_t *ostate) { -#if CENV_SYSF_BSDTIMEVAL +#if HAVE_SETITIMER struct itimerval itm; if (type != ITIMER_VIRTUAL) @@ -1127,7 +1127,7 @@ os_vtimer(ossighandler_t *irtn, uint32 usecs) void os_timer_restore(ostimer_t *ostate) { -#if CENV_SYSF_BSDTIMEVAL && CENV_SYSF_SIGSET +#if HAVE_SETITIMER && CENV_SYSF_SIGSET sigset_t blkset, savset; int ret; @@ -1161,7 +1161,7 @@ os_timer_restore(ostimer_t *ostate) void os_v2rt_idle(ossighandler_t *hdlarg) { -#if CENV_SYSF_BSDTIMEVAL && CENV_SYSF_SIGSET +#if HAVE_SETITIMER && CENV_SYSF_SIGSET sigset_t allmsk, oldmsk, nomsk; struct itimerval ntval, vtval; static ossighandler_t *handler = NULL; @@ -1234,7 +1234,7 @@ os_sleep(int secs) OS_STM_SET(stm, secs); while (os_msleep(&stm) > 0) ; -#elif CENV_SYSF_BSDTIMEVAL +#elif HAVE_SETITIMER /* Must save & restore ITIMER_REAL & SIGALRM, which conflict w/sleep() */ ostimer_t savetmr; @@ -1351,7 +1351,7 @@ os_rtm_tokst(register osrtm_t *art, register dw10_t d; register w10_t w; -#if CENV_SYSF_BSDTIMEVAL +#if HAVE_SETITIMER LRHSET(w, 017, 0507640); /* 4,100,000. */ d = op10xmul(w, op10utow(art->tv_sec)); w = op10utow((int32)((art->tv_usec << 2) + (art->tv_usec / 10))); @@ -1384,7 +1384,7 @@ os_rtm_tokst(register osrtm_t *art, unsigned long os_rtm_toqct(register osrtm_t *art) { -#if CENV_SYSF_BSDTIMEVAL +#if HAVE_SETITIMER return ((unsigned long)(art->tv_sec * 4100000) + (art->tv_usec << 2) + (art->tv_usec/10)) >> 4; #elif CENV_SYS_MAC @@ -1417,7 +1417,7 @@ See io_rdtime(). unsigned long os_rtm_toklt(register osrtm_t *art) { -#if CENV_SYSF_BSDTIMEVAL +#if HAVE_SETITIMER return ((unsigned long)art->tv_sec * 1000000) + art->tv_usec; #elif CENV_SYS_MAC return art->lo; diff --git a/src/osdsup.h b/src/osdsup.h index 52d8df2..12f5a4f 100644 --- a/src/osdsup.h +++ b/src/osdsup.h @@ -198,7 +198,13 @@ extern osintf_t os_swap(osintf_t *, int); /* Real-time - osrtm_t */ -#if CENV_SYSF_BSDTIMEVAL /* timeval is a BSD artifact */ +#if HAVE_SETITIMER && HAVE_GETTIMEOFDAY /* timeval is a BSD artifact */ + /* The of setitimer(2) and gettimeofday(struct timeval *, ...) + * are used together, and the latter implies the existence of + * struct timeval. + * Further checks will omit HAVE_GETTIMEOFDAY; if it's missing + * it will error out below anyway. + */ # include typedef struct timeval osrtm_t; # define OS_RTM_SEC(rtm) ((rtm).tv_sec) @@ -223,7 +229,7 @@ typedef struct { # define OS_ITIMER_VIRT 1 #endif ossigact_t ostmr_sigact; -#if CENV_SYSF_BSDTIMEVAL +#if HAVE_SETITIMER struct itimerval ostmr_itm; #elif CENV_SYS_MAC /* XXX: Mac implem uses static interval_timer* timer instead of a