summaryrefslogtreecommitdiffstats
path: root/libdimension/timer.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-12-01 00:29:34 -0500
committerTavian Barnes <tavianator@gmail.com>2010-12-01 00:30:16 -0500
commit94584e8b20f67a342c625a674590e8bc1aad88cb (patch)
treebd2662ad9b7dd27b1ca405a85bfcebf1097fe8ad /libdimension/timer.c
parent950fe8f2b1249369ab0b419b0063e6683bc8080e (diff)
downloaddimension-94584e8b20f67a342c625a674590e8bc1aad88cb.tar.xz
Check for platform support for times().
Diffstat (limited to 'libdimension/timer.c')
-rw-r--r--libdimension/timer.c34
1 files changed, 7 insertions, 27 deletions
diff --git a/libdimension/timer.c b/libdimension/timer.c
index 53d7101..fa96b06 100644
--- a/libdimension/timer.c
+++ b/libdimension/timer.c
@@ -23,44 +23,24 @@
* Performance counter.
*/
-#include "dimension.h"
-#include <sys/times.h>
-#include <unistd.h>
-
-/** Clock ticks per second. */
-static long clk_tck = 0;
+#include "dimension-impl.h"
dmnsn_timer *
dmnsn_new_timer(void)
{
- /* Figure out the clock ticks per second */
- if (!clk_tck) {
- clk_tck = sysconf(_SC_CLK_TCK);
- if (clk_tck == -1) {
- dmnsn_error(DMNSN_SEVERITY_MEDIUM, "sysconf(_SC_CLK_TCK) failed.");
- clk_tck = 1000000L;
- }
- }
-
dmnsn_timer *timer = dmnsn_malloc(sizeof(dmnsn_timer));
-
- struct tms buf;
- clock_t real = times(&buf);
- timer->real = (double)real/clk_tck;
- timer->user = (double)buf.tms_utime/clk_tck;
- timer->system = (double)buf.tms_stime/clk_tck;
-
+ dmnsn_get_times(timer);
return timer;
}
void
dmnsn_complete_timer(dmnsn_timer *timer)
{
- struct tms buf;
- clock_t real = times(&buf);
- timer->real = (double)real/clk_tck - timer->real;
- timer->user = (double)buf.tms_utime/clk_tck - timer->user;
- timer->system = (double)buf.tms_stime/clk_tck - timer->system;
+ dmnsn_timer now;
+ dmnsn_get_times(&now);
+ timer->real = now.real - timer->real;
+ timer->user = now.user - timer->user;
+ timer->system = now.system - timer->system;
}
void