From 90c5825855bdebadc6ea7683fab79f9523c64c21 Mon Sep 17 00:00:00 2001 From: dwarning Date: Sun, 20 Oct 2024 20:30:12 +0200 Subject: [PATCH] rm ftime for windows build by substitution with clock_gettime --- configure.ac | 9 +-------- src/frontend/resource.c | 6 ++++-- src/misc/misc_time.c | 5 ++--- src/sharedspice.c | 40 ++++++++++++++-------------------------- src/winmain.c | 12 +++++------- 5 files changed, 26 insertions(+), 46 deletions(-) diff --git a/configure.ac b/configure.ac index 4d5d55c37..e075d2d18 100644 --- a/configure.ac +++ b/configure.ac @@ -908,14 +908,7 @@ AC_STRUCT_TM AC_STRUCT_TIMEZONE AC_CHECK_FUNCS([localtime]) -case $host_os in - *mingw* | *msys* ) - AC_CHECK_FUNCS([clock_gettime gettimeofday times ftime]) - ;; - *) - AC_CHECK_FUNCS([clock_gettime gettimeofday times ftime]) - ;; -esac +AC_CHECK_FUNCS([clock_gettime gettimeofday times ftime]) # Do not use time or getrusage function for CPU time measurement under OpenMP if test "x$enable_openmp" = xno; then diff --git a/src/frontend/resource.c b/src/frontend/resource.c index 0851adeb2..abac8ef5f 100644 --- a/src/frontend/resource.c +++ b/src/frontend/resource.c @@ -77,6 +77,9 @@ init_rlimits(void) ft_ckspace(); } +#if defined HAVE_CLOCK_GETTIME || defined HAVE_GETTIMEOFDAY + PortableTime timebegin; +#endif void init_time(void) @@ -86,7 +89,6 @@ init_time(void) # ifdef HAVE_TIMES # else # if defined HAVE_CLOCK_GETTIME || defined HAVE_GETTIMEOFDAY - struct PortableTime timebegin; get_portable_time(&timebegin); # endif # endif @@ -192,7 +194,7 @@ printres(char *name) cpu_elapsed = "CPU"; # else #if defined HAVE_CLOCK_GETTIME || defined HAVE_GETTIMEOFDAY - struct PortableTime timenow; + PortableTime timenow; get_portable_time(&timenow); timediff(&timenow, &timebegin, &total_sec, &total_msec); cpu_elapsed = "elapsed"; diff --git a/src/misc/misc_time.c b/src/misc/misc_time.c index 5ef0bc18c..94665ae4a 100644 --- a/src/misc/misc_time.c +++ b/src/misc/misc_time.c @@ -48,8 +48,6 @@ datestring(void) #if defined HAVE_CLOCK_GETTIME || defined HAVE_GETTIMEOFDAY -PortableTime timebegin; - void timediff(PortableTime *now, PortableTime *begin, int *sec, int *msec) { @@ -111,7 +109,8 @@ seconds(void) #else #if defined HAVE_CLOCK_GETTIME || defined HAVE_GETTIMEOFDAY - struct PortableTime timenow; + PortableTime timenow; + PortableTime timebegin; int sec, msec; get_portable_time(&timenow); diff --git a/src/sharedspice.c b/src/sharedspice.c index a7d858414..dd0da8c88 100644 --- a/src/sharedspice.c +++ b/src/sharedspice.c @@ -155,10 +155,6 @@ static bool cont_condition; #include "ngspice/stringskip.h" #include "frontend/variable.h" -#ifdef HAVE_FTIME -#include -#endif - /* To interupt a spice run */ #include typedef void (*sighandler)(int); @@ -1892,26 +1888,26 @@ void SetAnalyse( static unsigned int ng_id1 = 0, ng_id2 = 0; bool thread1; -#ifdef HAVE_FTIME - struct timeb timenow; /* actual time stamp */ +#if defined HAVE_CLOCK_GETTIME || defined HAVE_GETTIMEOFDAY + PortableTime timenow; /* actual time stamp */ int diffsec, diffmillisec; /* differences actual minus prev. time stamp */ int result; /* return value from callback function */ char* s; /* outputs to callback function */ int OldPercent; /* Previous progress value */ char OldAn[128]; /* Previous analysis type */ char olds[128]; /* previous output */ - static struct timeb timebefore; /* previous time stamp */ + static PortableTime timebefore; /* previous time stamp */ /* thread 1 */ static int OldPercent1 = -2; /* Previous progress value */ static char OldAn1[128]; /* Previous analysis type */ static char olds1[128]; /* previous output */ - static struct timeb timebefore1; /* previous time stamp */ + static PortableTime timebefore1; /* previous time stamp */ /* thread2 */ static int OldPercent2 = -2; /* Previous progress value */ static char OldAn2[128]; /* Previous analysis type */ static char olds2[128]; /* previous output */ - static struct timeb timebefore2; /* previous time stamp */ + static PortableTime timebefore2; /* previous time stamp */ /*set the two thread ids */ unsigned int ng_idl = threadid_self(); @@ -1929,20 +1925,16 @@ void SetAnalyse( strcpy(OldAn, OldAn1); strcpy(olds, olds1); OldPercent = OldPercent1; - timebefore.dstflag = timebefore1.dstflag; - timebefore.millitm = timebefore1.millitm; - timebefore.time = timebefore1.time; - timebefore.timezone = timebefore1.timezone; + timebefore.milliseconds = timebefore1.milliseconds; + timebefore.seconds = timebefore1.seconds; } else if (ng_idl == ng_id2) { thread1 = FALSE; strcpy(OldAn, OldAn2); strcpy(olds, olds2); OldPercent = OldPercent2; - timebefore.dstflag = timebefore2.dstflag; - timebefore.millitm = timebefore2.millitm; - timebefore.time = timebefore2.time; - timebefore.timezone = timebefore2.timezone; + timebefore.milliseconds = timebefore2.milliseconds; + timebefore.seconds = timebefore2.seconds; } else return; @@ -1956,7 +1948,7 @@ void SetAnalyse( return; /* get actual time */ - ftime(&timenow); + get_portable_time(&timenow); timediff(&timenow, &timebefore, &diffsec, &diffmillisec); s = TMALLOC(char, 128); @@ -2007,16 +1999,12 @@ void SetAnalyse( sprintf( s, "%s: %3.1f%%", Analyse, (double)DecaPercent/10.); } if (thread1) { - timebefore1.dstflag = timenow.dstflag; - timebefore1.millitm = timenow.millitm; - timebefore1.time = timenow.time; - timebefore1.timezone = timenow.timezone; + timebefore1.milliseconds = timenow.milliseconds; + timebefore1.seconds = timenow.seconds; } else { - timebefore2.dstflag = timenow.dstflag; - timebefore2.millitm = timenow.millitm; - timebefore2.time = timenow.time; - timebefore2.timezone = timenow.timezone; + timebefore2.milliseconds = timenow.milliseconds; + timebefore2.seconds = timenow.seconds; } /* info when previous analysis period has finished */ if (strcmp(OldAn, Analyse)) { diff --git a/src/winmain.c b/src/winmain.c index 1bf3bb5fb..92dd22d64 100644 --- a/src/winmain.c +++ b/src/winmain.c @@ -220,8 +220,8 @@ SetAnalyse(char *Analyse, /* in: analysis type */ static int OldPercent = -2; /* Previous progress value */ static char OldAn[128]; /* Previous analysis type */ char s[128], t[128]; /* outputs to analysis window and task bar */ - static struct timeb timebefore; /* previous time stamp */ - struct timeb timenow; /* actual time stamp */ + static PortableTime timebefore; /* previous time stamp */ + PortableTime timenow; /* actual time stamp */ int diffsec, diffmillisec; /* differences actual minus prev. time stamp */ WaitForIdle(); @@ -232,7 +232,7 @@ SetAnalyse(char *Analyse, /* in: analysis type */ return; /* get actual time */ - ftime(&timenow); + get_portable_time(&timenow); timediff(&timenow, &timebefore, &diffsec, &diffmillisec); OldPercent = DecaPercent; @@ -255,10 +255,8 @@ SetAnalyse(char *Analyse, /* in: analysis type */ sprintf(s, " %s: %3.1f%%", Analyse, (double)DecaPercent/10.); sprintf(t, "%s %3.1f%%", PACKAGE_STRING, (double)DecaPercent/10.); } - timebefore.dstflag = timenow.dstflag; - timebefore.millitm = timenow.millitm; - timebefore.time = timenow.time; - timebefore.timezone = timenow.timezone; + timebefore.milliseconds = timenow.milliseconds; + timebefore.seconds = timenow.seconds; /* info when previous analysis period has finished */ if (strcmp(OldAn, Analyse)) { if ((ft_nginfo || ft_ngdebug) && (strcmp(OldAn, "")))