diff options
author | Philip Kelley <phkelley@hotmail.com> | 2013-09-21 18:25:54 -0400 |
---|---|---|
committer | Philip Kelley <phkelley@hotmail.com> | 2013-09-21 18:25:54 -0400 |
commit | e4987b6ce2db08d87463ef9291151ed6cb4839f2 (patch) | |
tree | 183c45773bade3212e67a4be3c823804d2302a93 /src/timing.c | |
parent | 37bf1bc129e10fec17e9d1cd9674f659fb01670f (diff) | |
download | libgit2-stopwatch.tar.gz |
Improvements to stopwatch implementationstopwatch
Diffstat (limited to 'src/timing.c')
-rw-r--r-- | src/timing.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/timing.c b/src/timing.c index cf729eab0..3125678e7 100644 --- a/src/timing.c +++ b/src/timing.c @@ -99,8 +99,14 @@ int git_stopwatch_query(double *out_elapsed_seconds, git_stopwatch *s) int git_stopwatch_start(git_stopwatch *s) { - if (clock_gettime(CLOCK_MONOTONIC, &s->start)) { - giterr_set(GITERR_OS, "Unable to get the monotonic timer"); + s->clk_id = GIT_PREFERRED_CLOCK; + + /* On EINVAL for the preferred clock, fall back to CLOCK_REALTIME */ + if (clock_gettime(s->clk_id, &s->start) && + (CLOCK_REALTIME == GIT_PREFERRED_CLOCK || errno != EINVAL || + clock_gettime(s->clk_id = CLOCK_REALTIME, &s->start))) { + giterr_set(GITERR_OS, "Unable to read the clock"); + s->running = 0; return -1; } @@ -119,8 +125,8 @@ int git_stopwatch_query(double *out_elapsed_seconds, git_stopwatch *s) return -1; } - if (clock_gettime(CLOCK_MONOTONIC, &end)) { - giterr_set(GITERR_OS, "Unable to get the monotonic timer"); + if (clock_gettime(s->clk_id, &end)) { + giterr_set(GITERR_OS, "Unable to read the clock"); return -1; } @@ -145,4 +151,4 @@ int git_stopwatch_query(double *out_elapsed_seconds, git_stopwatch *s) return 0; } -#endif
\ No newline at end of file +#endif |