diff options
author | Mathias Gumz <akira at fluxbox dot org> | 2013-01-26 08:21:47 (GMT) |
---|---|---|
committer | Mathias Gumz <akira at fluxbox dot org> | 2013-01-26 08:21:47 (GMT) |
commit | 716532dd47d718cb548da5f65b53a8b744ce235f (patch) | |
tree | 683de0875820ce361e2c02efc69d3ad103f3f90a /src/FbTk/FbTime.cc | |
parent | e7bfc639323bf5d4b207323b6e2fd275dcb5d825 (diff) | |
download | fluxbox_pavel-716532dd47d718cb548da5f65b53a8b744ce235f.zip fluxbox_pavel-716532dd47d718cb548da5f65b53a8b744ce235f.tar.bz2 |
Calculates timeouts of ClockTool based upon System Clock
Users expect time switches to happen upon system clock times. Calculating the
timeout for the next refresh of the shown time via the monotonic clock is
wrong: The monotonic clock yields values based upon some arbitrary point in
time which might be off a little bit to the system clock, a 'full' minute of
the monotonic clock might be in the midst of a system clock minute.
Diffstat (limited to 'src/FbTk/FbTime.cc')
-rw-r--r-- | src/FbTk/FbTime.cc | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/FbTk/FbTime.cc b/src/FbTk/FbTime.cc index d0ef731..c86edb1 100644 --- a/src/FbTk/FbTime.cc +++ b/src/FbTk/FbTime.cc | |||
@@ -21,6 +21,8 @@ | |||
21 | 21 | ||
22 | #include "FbTime.hh" | 22 | #include "FbTime.hh" |
23 | 23 | ||
24 | #include <cstdlib> | ||
25 | #include <sys/time.h> | ||
24 | 26 | ||
25 | 27 | ||
26 | #ifdef HAVE_CLOCK_GETTIME // linux|*bsd|solaris | 28 | #ifdef HAVE_CLOCK_GETTIME // linux|*bsd|solaris |
@@ -28,16 +30,16 @@ | |||
28 | 30 | ||
29 | namespace { | 31 | namespace { |
30 | 32 | ||
31 | uint64_t _now() { | 33 | uint64_t _mono() { |
32 | 34 | ||
33 | uint64_t n = 0L; | 35 | uint64_t t = 0L; |
34 | timespec ts; | 36 | timespec ts; |
35 | 37 | ||
36 | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { | 38 | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { |
37 | n = (ts.tv_sec * FbTk::FbTime::IN_SECONDS) + (ts.tv_nsec / 1000L); | 39 | t = (ts.tv_sec * FbTk::FbTime::IN_SECONDS) + (ts.tv_nsec / 1000L); |
38 | } | 40 | } |
39 | 41 | ||
40 | return n; | 42 | return t; |
41 | } | 43 | } |
42 | 44 | ||
43 | } | 45 | } |
@@ -59,7 +61,7 @@ uint64_t _now() { | |||
59 | 61 | ||
60 | namespace { | 62 | namespace { |
61 | 63 | ||
62 | uint64_t _now() { | 64 | uint64_t _mono() { |
63 | 65 | ||
64 | // mach_absolute_time() * info.numer / info.denom yields | 66 | // mach_absolute_time() * info.numer / info.denom yields |
65 | // nanoseconds. | 67 | // nanoseconds. |
@@ -85,13 +87,15 @@ uint64_t _now() { | |||
85 | 87 | ||
86 | 88 | ||
87 | 89 | ||
88 | 90 | uint64_t FbTk::FbTime::mono() { | |
89 | uint64_t FbTk::FbTime::now() { | 91 | return ::_mono(); |
90 | return ::_now(); | ||
91 | } | 92 | } |
92 | 93 | ||
93 | 94 | ||
94 | uint64_t FbTk::FbTime::remainingNext(uint64_t unit) { | 95 | uint64_t FbTk::FbTime::system() { |
95 | return (unit - (::_now() % unit) - 1); | 96 | static timeval v; |
97 | gettimeofday(&v, NULL); | ||
98 | return (v.tv_sec * FbTk::FbTime::IN_SECONDS) + v.tv_usec; | ||
96 | } | 99 | } |
97 | 100 | ||
101 | |||