emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master bb3e281236: Improve X server time computation


From: Po Lu
Subject: master bb3e281236: Improve X server time computation
Date: Wed, 3 Aug 2022 03:14:58 -0400 (EDT)

branch: master
commit bb3e281236bd39c2fbd0702c4f3e07dfaec7afe2
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Improve X server time computation
    
    * src/xterm.c (x_sync_get_monotonic_time): Use that if
    available.
    (x_display_set_last_user_time): Compute an offset between the
    monotonic time and the X server time if they are not identical.
    * src/xterm.h (struct x_display_info): New field
    `server_time_offset'.
---
 src/xterm.c | 15 +++++++++++++--
 src/xterm.h |  4 ++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/xterm.c b/src/xterm.c
index 2239b9fa4e..eb1a557e88 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -6645,7 +6645,11 @@ x_sync_get_monotonic_time (struct x_display_info 
*dpyinfo,
   if (dpyinfo->server_time_monotonic_p)
     return timestamp;
 
-  return 0;
+  /* This means we haven't yet initialized the server time offset.  */
+  if (!dpyinfo->server_time_offset)
+    return 0;
+
+  return timestamp - dpyinfo->server_time_offset;
 }
 
 /* Return the current monotonic time in the same format as a
@@ -7464,7 +7468,14 @@ x_display_set_last_user_time (struct x_display_info 
*dpyinfo, Time time,
          && time * 1000 < monotonic_time + 500 * 1000)
        dpyinfo->server_time_monotonic_p = true;
       else
-       dpyinfo->server_time_monotonic_p = false;
+       {
+         /* Compute an offset that can be subtracted from the server
+            time to estimate the monotonic time on the X server.  */
+
+         dpyinfo->server_time_monotonic_p = false;
+         dpyinfo->server_time_offset
+           = ((int64_t) time * 1000) - monotonic_time;
+       }
     }
 #endif
 
diff --git a/src/xterm.h b/src/xterm.h
index b656c8dcb2..fb099e92ea 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -774,6 +774,10 @@ struct x_display_info
   /* Whether or not the server time is probably the same as
      "clock_gettime (CLOCK_MONOTONIC, ...)".  */
   bool server_time_monotonic_p;
+
+  /* The time difference between the X server clock and the monotonic
+     clock.  */
+  int64_t server_time_offset;
 #endif
 };
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]