diff options
| author | Paul Eggert | 2025-09-27 11:23:59 -0700 |
|---|---|---|
| committer | Paul Eggert | 2025-09-27 12:26:24 -0700 |
| commit | 5e06aa209bc906cf16f2e3de622a189bec34aa78 (patch) | |
| tree | 0d5541355f0f4d7777475f2534a20795e9302ff5 /src | |
| parent | 3cdc615218458729b51a715bedc899e3df5bfa64 (diff) | |
| download | emacs-5e06aa209bc906cf16f2e3de622a189bec34aa78.tar.gz emacs-5e06aa209bc906cf16f2e3de622a189bec34aa78.zip | |
Prefer coarse timestamps when using X sync
They are good enough for this purpose, and are cheaper to get.
* src/timefns.c (monotonic_coarse_timespec): New function.
* src/xterm.c [HAVE_XSYNC && !USE_GTK && HAVE_CLOCK_GETTIME]:
(x_sync_current_monotonic_time): Use it.
(CLOCK_MONOTONIC): Remove; no longer uneeded here.
Diffstat (limited to 'src')
| -rw-r--r-- | src/systime.h | 1 | ||||
| -rw-r--r-- | src/timefns.c | 20 | ||||
| -rw-r--r-- | src/xterm.c | 11 |
3 files changed, 23 insertions, 9 deletions
diff --git a/src/systime.h b/src/systime.h index 22ede456840..2e8fb454eee 100644 --- a/src/systime.h +++ b/src/systime.h | |||
| @@ -79,6 +79,7 @@ enum { LO_TIME_BITS = 16 }; | |||
| 79 | 79 | ||
| 80 | /* defined in timefns.c */ | 80 | /* defined in timefns.c */ |
| 81 | extern struct timeval make_timeval (struct timespec) ATTRIBUTE_CONST; | 81 | extern struct timeval make_timeval (struct timespec) ATTRIBUTE_CONST; |
| 82 | extern struct timespec monotonic_coarse_timespec (void); | ||
| 82 | extern Lisp_Object make_lisp_time (struct timespec); | 83 | extern Lisp_Object make_lisp_time (struct timespec); |
| 83 | extern Lisp_Object timespec_to_lisp (struct timespec); | 84 | extern Lisp_Object timespec_to_lisp (struct timespec); |
| 84 | extern struct timespec list4_to_timespec (Lisp_Object, Lisp_Object, | 85 | extern struct timespec list4_to_timespec (Lisp_Object, Lisp_Object, |
diff --git a/src/timefns.c b/src/timefns.c index 8cf424bbe7e..b4baeaaff82 100644 --- a/src/timefns.c +++ b/src/timefns.c | |||
| @@ -138,6 +138,26 @@ make_timeval (struct timespec t) | |||
| 138 | return tv; | 138 | return tv; |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | /* Return the current time with an epoch specific to this Emacs instance | ||
| 142 | (e.g., system boot). The clock should be unaffected by changes to | ||
| 143 | the system time, and should be cheap to access. Its resolution | ||
| 144 | should be appropriate for human time scales, e.g., better than 10 ms. | ||
| 145 | Make do with realtime if such a clock is not available. */ | ||
| 146 | struct timespec | ||
| 147 | monotonic_coarse_timespec (void) | ||
| 148 | { | ||
| 149 | struct timespec ts; | ||
| 150 | #ifdef CLOCK_MONOTONIC_COARSE | ||
| 151 | if (clock_gettime (CLOCK_MONOTONIC_COARSE, &ts) == 0) | ||
| 152 | return ts; | ||
| 153 | #elif defined CLOCK_MONOTONIC | ||
| 154 | if (clock_gettime (CLOCK_MONOTONIC, &ts) == 0) | ||
| 155 | return ts; | ||
| 156 | #endif | ||
| 157 | ts = current_timespec (); | ||
| 158 | return ts; | ||
| 159 | } | ||
| 160 | |||
| 141 | /* Yield A's UTC offset, or an unspecified value if unknown. */ | 161 | /* Yield A's UTC offset, or an unspecified value if unknown. */ |
| 142 | static long int | 162 | static long int |
| 143 | tm_gmtoff (struct tm *a) | 163 | tm_gmtoff (struct tm *a) |
diff --git a/src/xterm.c b/src/xterm.c index d520ac1bdf5..e47a836713a 100644 --- a/src/xterm.c +++ b/src/xterm.c | |||
| @@ -7067,22 +7067,15 @@ x_sync_get_monotonic_time (struct x_display_info *dpyinfo, | |||
| 7067 | return ckd_sub (&t, timestamp, dpyinfo->server_time_offset) ? 0 : t; | 7067 | return ckd_sub (&t, timestamp, dpyinfo->server_time_offset) ? 0 : t; |
| 7068 | } | 7068 | } |
| 7069 | 7069 | ||
| 7070 | # ifndef CLOCK_MONOTONIC | ||
| 7071 | # define CLOCK_MONOTONIC CLOCK_REALTIME | ||
| 7072 | # endif | ||
| 7073 | |||
| 7074 | /* Return the current monotonic time in the same format as a | 7070 | /* Return the current monotonic time in the same format as a |
| 7075 | high-resolution server timestamp, or 0 if not available. */ | 7071 | high-resolution server timestamp, or 0 if not available. */ |
| 7076 | 7072 | ||
| 7077 | static uint_fast64_t | 7073 | static uint_fast64_t |
| 7078 | x_sync_current_monotonic_time (void) | 7074 | x_sync_current_monotonic_time (void) |
| 7079 | { | 7075 | { |
| 7080 | struct timespec time; | 7076 | struct timespec time = monotonic_coarse_timespec (); |
| 7081 | uint_fast64_t t; | 7077 | uint_fast64_t t; |
| 7082 | return (((clock_gettime (CLOCK_MONOTONIC, &time) != 0 | 7078 | return ((ckd_mul (&t, time.tv_sec, 1000000) |
| 7083 | && (CLOCK_MONOTONIC == CLOCK_REALTIME | ||
| 7084 | || clock_gettime (CLOCK_REALTIME, &time) != 0)) | ||
| 7085 | || ckd_mul (&t, time.tv_sec, 1000000) | ||
| 7086 | || ckd_add (&t, t, time.tv_nsec / 1000)) | 7079 | || ckd_add (&t, t, time.tv_nsec / 1000)) |
| 7087 | ? 0 : t); | 7080 | ? 0 : t); |
| 7088 | } | 7081 | } |