[PATCH xserver 2/4] os: Use separate clockid for GetTimeInMicros()
Jeff Smith
whydoubt at gmail.com
Wed Dec 27 04:10:53 UTC 2017
Prior to commit a779fda2 (xwayland: Use the CLOCK_MONOTONIC clock),
GetTimeInMillis() and GetTimeInMicros() had separate clockid's. As a
part of making them available to ForceClockId(), that commit replaced
them with a single clockid, whose value depended on which GetTime
function got called first.
Return to using separate clockid's, with ForceClockId() checking and
setting both values if called.
Signed-off-by: Jeff Smith <whydoubt at gmail.com>
---
os/utils.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/os/utils.c b/os/utils.c
index 4a8d124..876841c 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -201,6 +201,7 @@ sig_atomic_t inSignalContext = FALSE;
#ifdef MONOTONIC_CLOCK
static clockid_t clockid;
+static clockid_t clockid_micro;
#endif
OsSigHandlerPtr
@@ -426,15 +427,17 @@ ForceClockId(clockid_t forced_clockid)
{
struct timespec tp;
- BUG_RETURN (clockid);
+ BUG_RETURN(clockid);
+ BUG_RETURN(clockid_micro);
- clockid = forced_clockid;
-
- if (clock_gettime(clockid, &tp) != 0) {
+ if (clock_gettime(forced_clockid, &tp) != 0) {
FatalError("Forced clock id failed to retrieve current time: %s\n",
strerror(errno));
return;
}
+
+ clockid = forced_clockid;
+ clockid_micro = forced_clockid;
}
#endif
@@ -486,13 +489,13 @@ GetTimeInMicros(void)
#ifdef MONOTONIC_CLOCK
struct timespec tp;
- if (!clockid) {
+ if (!clockid_micro) {
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
- clockid = CLOCK_MONOTONIC;
+ clockid_micro = CLOCK_MONOTONIC;
else
- clockid = ~0L;
+ clockid_micro = ~0L;
}
- if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
+ if (clockid_micro != ~0L && clock_gettime(clockid_micro, &tp) == 0)
return (CARD64) tp.tv_sec * (CARD64)1000000 + tp.tv_nsec / 1000;
#endif
--
2.9.4
More information about the xorg-devel
mailing list