diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2017-02-20 00:05:25 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2017-02-20 00:05:25 -0800 |
commit | db04688faa20f3576257c0fe41752ec435beab9a (patch) | |
tree | 6d638c2e1f65afd5f49d20b2d22ce35bd74705ff /time.c | |
parent | 1edcb9b62a1a520eddae8403c19d841c9b18737f (diff) | |
download | scm-db04688faa20f3576257c0fe41752ec435beab9a.tar.gz scm-db04688faa20f3576257c0fe41752ec435beab9a.zip |
Import Upstream version 5c3upstream/5c3
Diffstat (limited to 'time.c')
-rw-r--r-- | time.c | 329 |
1 files changed, 159 insertions, 170 deletions
@@ -44,177 +44,146 @@ #include "scm.h" -#ifdef HAVE_CONFIG_H - -# ifndef HAVE_FTIME -# define LACK_FTIME +#ifdef STDC_HEADERS +# include <time.h> +# ifdef M_SYSV +# include <sys/types.h> +# include <sys/times.h> # endif -# ifndef HAVE_TIMES -# define LACK_TIMES +# ifdef sun +# include <sys/types.h> +# include <sys/times.h> # endif -# ifdef HAVE_SYS_TYPES_H +# ifdef ultrix # include <sys/types.h> +# include <sys/times.h> # endif -# ifdef TIME_WITH_SYS_TIME -# include <sys/time.h> -# include <time.h> -# else -# ifdef HAVE_SYS_TIME_H -# include <sys/time.h> -# else -# ifdef HAVE_TIME_H -# include <time.h> -# endif -# endif +# ifdef nosve +# include <sys/types.h> +# include <sys/times.h> # endif -# ifdef HAVE_SYS_TIMES_H +# ifdef _UNICOS +# include <sys/types.h> # include <sys/times.h> -# else -# ifdef HAVE_SYS_TIMEB_H -# include <sys/timeb.h> -# endif # endif -# ifdef HAVE_FTIME -# ifdef unix -# ifndef GO32 -# include <sys/timeb.h> -# endif -# else -# ifdef __amigados__ -# include <sys/timeb.h> -# endif -# endif +# ifdef __IBMC__ +# include <sys/timeb.h> # endif - #else - -# ifdef STDC_HEADERS +# ifdef SVR2 # include <time.h> -# ifdef M_SYSV -# include <sys/types.h> -# include <sys/times.h> -# endif -# ifdef sun -# include <sys/types.h> -# include <sys/times.h> -# endif -# ifdef ultrix -# include <sys/types.h> -# include <sys/times.h> -# endif -# ifdef nosve -# include <sys/types.h> -# include <sys/times.h> -# endif -# ifdef _UNICOS -# include <sys/types.h> -# include <sys/times.h> -# endif -# ifdef __IBMC__ -# include <sys/timeb.h> -# endif # else -# ifdef SVR2 -# include <time.h> -# else -# ifndef ARM_ULIB -# include <sys/time.h> -# else -# include <time.h> -# endif -# endif -# include <sys/types.h> - # ifndef ARM_ULIB -# include <sys/times.h> +# include <sys/time.h> # else # include <time.h> # endif +# endif +# include <sys/types.h> +# ifndef ARM_ULIB +# include <sys/times.h> +# else +# include <time.h> # endif +#endif + /* Define this if your system lacks ftime(). */ /* #define LACK_FTIME */ +/* Define this if your system has gettimeofday() + (LACK_FTIME should not be defined). */ +/* #define USE_GETTIMEOFDAY */ /* Define this if your system lacks times(). */ /* #define LACK_TIMES */ -# ifdef __TURBOC__ -# define LACK_TIMES -# endif -# if (__TURBOC__==1) /* Needed for TURBOC V1.0 */ -# define LACK_FTIME -# undef MSDOS -# endif -# ifdef __HIGHC__ -# define LACK_TIMES -# endif -# ifdef THINK_C -# define LACK_FTIME -# define LACK_TIMES -# define CLK_TCK 60 -# endif -# ifdef SVR2 -# define LACK_FTIME -# endif -# ifdef SVR4 -# define LACK_FTIME -# endif -# ifdef __svr4__ -# define LACK_FTIME -# endif -# ifdef nosve -# define LACK_FTIME -# endif -# ifdef GO32 -# define LACK_FTIME -# define LACK_TIMES -# endif -# ifdef atarist -# define LACK_FTIME -# define LACK_TIMES -# endif -# ifdef ARM_ULIB -# define LACK_FTIME -# define LACK_TIMES -# endif -# ifdef _DCC -# define LACK_FTIME +#ifdef linux +# include <sys/types.h> +# include <sys/time.h> +# include <sys/timeb.h> +# define USE_GETTIMEOFDAY +#endif +#ifdef freebsd +# include <sys/types.h> +# include <sys/time.h> +# include <sys/timeb.h> +# define USE_GETTIMEOFDAY +#endif +#ifdef __TURBOC__ +# define LACK_TIMES +#endif +#if (__TURBOC__==1) /* Needed for TURBOC V1.0 */ +# define LACK_FTIME +# undef MSDOS +#endif +#ifdef __HIGHC__ +# define LACK_TIMES +#endif +#ifdef macintosh +# define LACK_FTIME +# define LACK_TIMES +# define CLK_TCK 60 +#endif +#ifdef SVR2 +# define LACK_FTIME +#endif +#ifdef SVR4 +# define LACK_FTIME +#endif +#ifdef __svr4__ +# define LACK_FTIME +#endif +#ifdef nosve +# define LACK_FTIME +#endif +#ifdef GO32 +# define LACK_FTIME +# define LACK_TIMES +#endif +#ifdef atarist +# define LACK_FTIME +# define LACK_TIMES +#endif +#ifdef ARM_ULIB +# define LACK_FTIME +# define LACK_TIMES +#endif +#ifdef _DCC +# define LACK_FTIME +#endif +#ifdef MSDOS +# ifndef GO32 +# include <sys/types.h> +# include <sys/timeb.h> # endif -# ifdef MSDOS +#endif +#ifdef _UNICOS +# define LACK_FTIME +#endif + +#ifndef LACK_FTIME +# ifdef unix # ifndef GO32 -# include <sys/types.h> # include <sys/timeb.h> # endif # endif -# ifdef _UNICOS -# define LACK_FTIME -# endif - -# ifndef LACK_FTIME -# ifdef unix -# ifndef GO32 -# include <sys/timeb.h> -# endif -# endif -# endif - -# ifdef __EMX__ -# define LACK_TIMES -# include <sys/types.h> -# include <sys/timeb.h> -# endif +#endif -# ifdef MWC -# include <time.h> -# include <sys/timeb.h> -# endif +#ifdef __EMX__ +# define LACK_TIMES +# include <sys/types.h> +# include <sys/timeb.h> +#endif -# ifdef ARM_ULIB -# include <sys/types.h> -# include <time.h> -# endif +#ifdef MWC +# include <time.h> +# include <sys/timeb.h> +#endif -#endif /* HAVE_CONFIG_H */ +#ifdef ARM_ULIB +# include <sys/types.h> +# include <time.h> +#endif #ifdef vms # define LACK_TIMES @@ -327,18 +296,48 @@ SCM your_time() } # endif /* AMIGA */ #else /* LACK_FTIME */ +# ifdef USE_GETTIMEOFDAY +int scm_ftime(time_buffer) + struct timeb *time_buffer; +{ + struct timezone t_z; struct timeval t_v; + if (gettimeofday(&t_v, &t_z) < 0) return -1; + time_buffer->timezone = t_z.tz_minuteswest; + time_buffer->dstflag = t_z.tz_dsttime; + time_buffer->millitm = t_v.tv_usec / 1000; + time_buffer->time = t_v.tv_sec; + return 0;} +# else /* USE_GETTIMEOFDAY */ +# define scm_ftime ftime +# endif /* USE_GETTIMEOFDAY */ struct timeb your_base = {0}; +# define TIMETRIES 10 SCM your_time() { - struct timeb time_buffer; - long tmp; - ftime(&time_buffer); - time_buffer.time -= your_base.time; - tmp = time_buffer.millitm - your_base.millitm; - tmp = time_buffer.time*1000L + tmp; - tmp *= CLKTCK; - tmp /= 1000; - return MAKINUM(tmp); + long tmp; + struct timeb time_buffer1; + struct timeb time_buffer2; + int cnt = 0; + tryagain: + cnt++; + scm_ftime(&time_buffer1); + scm_ftime(&time_buffer2); + if (time_buffer1.time==time_buffer2.time) { + if (time_buffer1.millitm > time_buffer2.millitm) + time_buffer2.time = time_buffer2.time + 1; + } + else if ((1 + time_buffer1.time)==time_buffer2.time) ; + else if (cnt < TIMETRIES) goto tryagain; + else { + warn("could not read two ftime()s within one second in 10 tries",0L); + return MAKINUM(-1); + } + time_buffer2.time -= your_base.time; + tmp = time_buffer2.millitm - your_base.millitm; + tmp = time_buffer2.time*1000L + tmp; + tmp *= CLKTCK; + tmp /= 1000; + return MAKINUM(tmp); } #endif /* LACK_FTIME */ @@ -377,32 +376,22 @@ static iproc subr0s[] = { {"current-time", curtime}, {0, 0}}; -void init_time() +void reset_time() { - sysintern("internal-time-units-per-second", - MAKINUM((long)CLKTCK)); #ifdef LACK_FTIME # ifndef AMIGA - if (!your_base) time(&your_base); + time(&your_base); # endif #else - if (!your_base.time) ftime(&your_base); + scm_ftime(&your_base); #endif - if (!my_base) my_base = mytime(); - init_iprocs(subr0s, tc7_subr_0); + my_base = 0; + my_base = mytime(); } -#ifdef freebsd -# include <sys/types.h> -# include <sys/time.h> -# include <sys/timeb.h> -int ftime(time_buffer) - struct timeb *time_buffer; +void init_time() { - struct timezone t_z; struct timeval t_v; - if (gettimeofday(&t_v, &t_z) < 0) return -1; - time_buffer->timezone = t_z.tz_minuteswest; - time_buffer->dstflag = t_z.tz_dsttime; - time_buffer->millitm = t_v.tv_usec / 1000; - time_buffer->time = t_v.tv_sec; - return 0;} -#endif + sysintern("internal-time-units-per-second", + MAKINUM((long)CLKTCK)); + reset_time(); + init_iprocs(subr0s, tc7_subr_0); +} |