summary refs log tree commit diff
path: root/Src/jobs.c
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2014-05-29 21:40:33 +0100
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2014-05-29 21:40:33 +0100
commit880020ca2ed8207fe39aa95169a6f9226ff7b8dc (patch)
tree79483423b8e155062c311cbf7ce057be5b1905e5 /Src/jobs.c
parent5554cf8244aaa4e7bf5f153e66cd5db64e50c6e4 (diff)
downloadzsh-880020ca2ed8207fe39aa95169a6f9226ff7b8dc.tar.gz
zsh-880020ca2ed8207fe39aa95169a6f9226ff7b8dc.tar.xz
zsh-880020ca2ed8207fe39aa95169a6f9226ff7b8dc.zip
32624: use correct scaling factor (clock ticks) for times
Diffstat (limited to 'Src/jobs.c')
-rw-r--r--Src/jobs.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/Src/jobs.c b/Src/jobs.c
index 871946598..c4a0707d4 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -618,13 +618,11 @@ setprevjob(void)
 }
 
 /**/
-#ifndef HAVE_GETRUSAGE
-static long clktck = 0;
-
-/**/
-static void
-set_clktck(void)
+long
+get_clktck(void)
 {
+    static long clktck;
+
 #ifdef _SC_CLK_TCK
     if (!clktck)
 	/* fetch clock ticks per second from *
@@ -646,9 +644,9 @@ set_clktck(void)
 #  endif
 # endif
 #endif
+
+     return clktck;
 }
-/**/
-#endif
 
 /**/
 static void
@@ -698,11 +696,13 @@ printtime(struct timeval *real, child_times_t *ti, char *desc)
     percent = 100.0 * total_time
 	/ (real->tv_sec + real->tv_usec / 1000000.0);
 #else
-    set_clktck();
-    user_time    = ti->ut / (double) clktck;
-    system_time  = ti->st / (double) clktck;
-    percent      =  100.0 * (ti->ut + ti->st)
-	/ (clktck * real->tv_sec + clktck * real->tv_usec / 1000000.0);
+    {
+	long clktck = get_clktck();
+	user_time    = ti->ut / (double) clktck;
+	system_time  = ti->st / (double) clktck;
+	percent      =  100.0 * (ti->ut + ti->st)
+	    / (clktck * real->tv_sec + clktck * real->tv_usec / 1000000.0);
+    }
 #endif
 
     queue_signals();
@@ -910,8 +910,10 @@ should_report_time(Job j)
 	reporttime--;
     return reporttime <= 0;
 #else
-    set_clktck();
-    return ((j->procs->ti.ut + j->procs->ti.st) / clktck >= reporttime);
+    {
+	clktck = get_clktck();
+	return ((j->procs->ti.ut + j->procs->ti.st) / clktck >= reporttime);
+    }
 #endif
 }