diff options
Diffstat (limited to 'contrib/libf2c/libU77/dtime_.c')
-rw-r--r-- | contrib/libf2c/libU77/dtime_.c | 84 |
1 files changed, 43 insertions, 41 deletions
diff --git a/contrib/libf2c/libU77/dtime_.c b/contrib/libf2c/libU77/dtime_.c index 19100e6..dc9a863 100644 --- a/contrib/libf2c/libU77/dtime_.c +++ b/contrib/libf2c/libU77/dtime_.c @@ -44,19 +44,8 @@ Boston, MA 02111-1307, USA. */ #include <errno.h> /* for ENOSYS */ #include "f2c.h" -/* For dtime, etime we store the clock tick parameter (clk_tck) the - first time either of them is invoked rather than each time. This - approach probably speeds up each invocation by avoiding a system - call each time, but means that the overhead of the first call is - different to all others. */ -static long clk_tck = 0; - -#ifdef KR_headers -double G77_dtime_0 (tarray) - real tarray[2]; -#else -double G77_dtime_0 (real tarray[2]) -#endif +double +G77_dtime_0 (real tarray[2]) { #if defined (_WIN32) static int win32_platform = -1; @@ -68,7 +57,7 @@ double G77_dtime_0 (real tarray[2]) GetVersionEx (&osv); win32_platform = osv.dwPlatformId; } - + /* We need to use this hack on non-NT platforms, where the first call returns 0.0 and subsequent ones return the correct value. */ if (win32_platform != VER_PLATFORM_WIN32_NT) @@ -82,7 +71,7 @@ double G77_dtime_0 (real tarray[2]) if (clock_freq == 0) { LARGE_INTEGER freq; - if (! QueryPerformanceFrequency (&freq)) + if (!QueryPerformanceFrequency (&freq)) { errno = ENOSYS; return 0.0; @@ -90,15 +79,15 @@ double G77_dtime_0 (real tarray[2]) else { clock_freq = ((unsigned long long) freq.HighPart << 32) - + ((unsigned) freq.LowPart); + + ((unsigned) freq.LowPart); } } - if (! QueryPerformanceCounter (&counter_val)) + if (!QueryPerformanceCounter (&counter_val)) return -1.0; count = ((unsigned long long) counter_val.HighPart << 32) - + (unsigned) counter_val.LowPart; + + (unsigned) counter_val.LowPart; delta = ((double) (count - old_count)) / clock_freq; tarray[0] = (float) delta; tarray[1] = 0.0; @@ -112,10 +101,10 @@ double G77_dtime_0 (real tarray[2]) GetProcessTimes (GetCurrentProcess (), &creation_time, &exit_time, &kernel_time, &user_time); - utime = ((unsigned long long) user_time.dwHighDateTime << 32) - + (unsigned) user_time.dwLowDateTime; - stime = ((unsigned long long) kernel_time.dwHighDateTime << 32) - + (unsigned) kernel_time.dwLowDateTime; + utime = ((unsigned long long) user_time.dwHighDateTime << 32) + + (unsigned) user_time.dwLowDateTime; + stime = ((unsigned long long) kernel_time.dwHighDateTime << 32) + + (unsigned) kernel_time.dwLowDateTime; tarray[0] = (utime - old_utime) / 1.0e7; tarray[1] = (stime - old_stime) / 1.0e7; @@ -131,15 +120,21 @@ double G77_dtime_0 (real tarray[2]) static float old_utime = 0.0, old_stime = 0.0; struct rusage rbuff; - if (getrusage (RUSAGE_SELF, &rbuff) != 0) - abort (); - utime = (float) (rbuff.ru_utime).tv_sec + - (float) (rbuff.ru_utime).tv_usec/1000000.0; - tarray[0] = utime - (float) old_utime; - stime = (float) (rbuff.ru_stime).tv_sec + - (float) (rbuff.ru_stime).tv_usec/1000000.0; + if (getrusage (RUSAGE_SELF, &rbuff) != 0) + abort (); + utime = (float) (rbuff.ru_utime).tv_sec + + (float) (rbuff.ru_utime).tv_usec / 1000000.0; + tarray[0] = utime - (float) old_utime; + stime = (float) (rbuff.ru_stime).tv_sec + + (float) (rbuff.ru_stime).tv_usec / 1000000.0; tarray[1] = stime - old_stime; -#else /* HAVE_GETRUSAGE */ +#else /* HAVE_GETRUSAGE */ + /* For dtime, etime we store the clock tick parameter (clk_tck) the + first time either of them is invoked rather than each time. This + approach probably speeds up each invocation by avoiding a system + call each time, but means that the overhead of the first call is + different to all others. */ + static long clk_tck = 0; time_t utime, stime; static time_t old_utime = 0, old_stime = 0; struct tms buffer; @@ -147,24 +142,31 @@ double G77_dtime_0 (real tarray[2]) /* NeXTStep seems to define _SC_CLK_TCK but not to have sysconf; fixme: does using _POSIX_VERSION help? */ # if defined _SC_CLK_TCK && defined _POSIX_VERSION - if (! clk_tck) clk_tck = sysconf(_SC_CLK_TCK); + if (!clk_tck) + clk_tck = sysconf (_SC_CLK_TCK); # elif defined CLOCKS_PER_SECOND - if (! clk_tck) clk_tck = CLOCKS_PER_SECOND; + if (!clk_tck) + clk_tck = CLOCKS_PER_SECOND; # elif defined CLK_TCK - if (! clk_tck) clk_tck = CLK_TCK; + if (!clk_tck) + clk_tck = CLK_TCK; # elif defined HZ - if (! clk_tck) clk_tck = HZ; + if (!clk_tck) + clk_tck = HZ; # elif defined HAVE_GETRUSAGE # else - #error Dont know clock tick length +#error Dont know clock tick length # endif - if (times(&buffer) == (clock_t)-1) return -1.0; - utime = buffer.tms_utime; stime = buffer.tms_stime; - tarray[0] = ((float)(utime - old_utime)) / (float)clk_tck; - tarray[1] = ((float)(stime - old_stime)) / (float)clk_tck; + if (times (&buffer) == (clock_t) - 1) + return -1.0; + utime = buffer.tms_utime; + stime = buffer.tms_stime; + tarray[0] = ((float) (utime - old_utime)) / (float) clk_tck; + tarray[1] = ((float) (stime - old_stime)) / (float) clk_tck; #endif /* HAVE_GETRUSAGE */ - old_utime = utime; old_stime = stime; - return (tarray[0]+tarray[1]); + old_utime = utime; + old_stime = stime; + return (tarray[0] + tarray[1]); #else /* ! HAVE_GETRUSAGE && ! HAVE_TIMES */ errno = ENOSYS; return 0.0; |