xwayland: Use the CLOCK_MONOTONIC clock

By default the X server will try CLOCK_MONOTONIC_COARSE before
CLOCK_MONOTONIC, while A Wayland compositor may only support getting
their timestamps from the CLOCK_MONOTONIC clock. This causes various
issues since it may happen that a timestamp from CLOCK_MONOTONIC
retrieved before a sending an X request will still be "later" than the
timestamp the X server than gets after receiving the request, due to the
fact that CLOCK_MONOTONIC_COARSE has a lower resolution.

To avoid these issues, make Xwayland always use CLOCK_MONOTONIC, so
that it becomes possible for Wayland compositor only supporting
CLOCK_MONOTONIC and X server to use the same clock.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Acked-by: Daniel Stone <daniels@collabora.com>
Tested-by: Olivier Fourdan <ofourdan@redhat.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Jonas Ådahl
2016-05-24 18:46:42 +08:00
committed by Peter Hutterer
parent 28b2c880a9
commit a779fda224
4 changed files with 35 additions and 2 deletions

View File

@@ -210,6 +210,10 @@ sig_atomic_t inSignalContext = FALSE;
#define HAS_SAVED_IDS_AND_SETEUID
#endif
#ifdef MONOTONIC_CLOCK
static clockid_t clockid;
#endif
OsSigHandlerPtr
OsSignal(int sig, OsSigHandlerPtr handler)
{
@@ -427,6 +431,24 @@ GiveUp(int sig)
errno = olderrno;
}
#ifdef MONOTONIC_CLOCK
void
ForceClockId(clockid_t forced_clockid)
{
struct timespec tp;
BUG_RETURN (clockid);
clockid = forced_clockid;
if (clock_gettime(clockid, &tp) != 0) {
FatalError("Forced clock id failed to retrieve current time: %s\n",
strerror(errno));
return;
}
}
#endif
#if (defined WIN32 && defined __MINGW32__) || defined(__CYGWIN__)
CARD32
GetTimeInMillis(void)
@@ -446,7 +468,6 @@ GetTimeInMillis(void)
#ifdef MONOTONIC_CLOCK
struct timespec tp;
static clockid_t clockid;
if (!clockid) {
#ifdef CLOCK_MONOTONIC_COARSE
@@ -475,7 +496,6 @@ GetTimeInMicros(void)
struct timeval tv;
#ifdef MONOTONIC_CLOCK
struct timespec tp;
static clockid_t clockid;
if (!clockid) {
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)