aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2012-07-10 16:24:36 -0700
committerPaul Eggert2012-07-10 16:24:36 -0700
commite9a9ae0350689d352c2bdfa3af0eb722f587b966 (patch)
tree10ed0298079b06838a525f0a4df780d7600e13fe /src
parentffacb12679a1e001981c2e0f690b327eda652d04 (diff)
downloademacs-e9a9ae0350689d352c2bdfa3af0eb722f587b966.tar.gz
emacs-e9a9ae0350689d352c2bdfa3af0eb722f587b966.zip
EMACS_TIME simplification (Bug#11875).
This replaces macros (which typically do not work in GDB) with functions, typedefs and enums, making the code easier to debug. The functional style also makes code easier to read and maintain. * lib-src/profile.c (TV2): Remove no-longer-needed static var. * src/systime.h: Include <sys/time.h> on all hosts, not just if WINDOWSNT, since 'struct timeval' is needed in general. (EMACS_TIME): Now a typedef, not a macro. (EMACS_TIME_RESOLUTION, LOG10_EMACS_TIME_RESOLUTION): Now constants, not macros. (EMACS_SECS, EMACS_NSECS, EMACS_TIME_SIGN, EMACS_TIME_VALID_P) (EMACS_TIME_FROM_DOUBLE, EMACS_TIME_TO_DOUBLE, EMACS_TIME_EQ) (EMACS_TIME_NE, EMACS_TIME_GT, EMACS_TIME_GE, EMACS_TIME_LT) (EMACS_TIME_LE): Now functions, not macros. (EMACS_SET_SECS, EMACS_SET_NSECS, EMACS_SET_SECS_NSECS) (EMACS_SET_USECS, EMACS_SET_SECS_USECS): Remove these macros, which are not functions. All uses rewritten to use: (make_emacs_time): New function. (EMACS_SECS_ADDR, EMACS_SET_INVALID_TIME, EMACS_GET_TIME) (EMACS_ADD_TIME, EMACS_SUB_TIME): Remove these macros, which are not functions. All uses rewritten to use the following, respectively: (emacs_secs_addr, invalid_emacs_time, get_emacs_time) (add_emacs_time, sub_emacs_time): New functions. * src/atimer.c: Don't include <sys/time.h>, as "systime.h" does this. * src/fileio.c (Fcopy_file): * src/xterm.c (XTflash): Get the current time closer to when it's used. * src/makefile.w32-in ($(BLD)/atimer.$(O)): Update dependencies.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog27
-rw-r--r--src/alloc.c8
-rw-r--r--src/atimer.c34
-rw-r--r--src/buffer.c2
-rw-r--r--src/dispnew.c22
-rw-r--r--src/editfns.c24
-rw-r--r--src/fileio.c26
-rw-r--r--src/fns.c3
-rw-r--r--src/image.c8
-rw-r--r--src/keyboard.c77
-rw-r--r--src/lread.c3
-rw-r--r--src/makefile.w32-in1
-rw-r--r--src/msdos.c8
-rw-r--r--src/nsterm.m15
-rw-r--r--src/process.c41
-rw-r--r--src/sysdep.c36
-rw-r--r--src/systime.h150
-rw-r--r--src/undo.c6
-rw-r--r--src/w32.c2
-rw-r--r--src/xdisp.c8
-rw-r--r--src/xgselect.c4
-rw-r--r--src/xterm.c27
22 files changed, 268 insertions, 264 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index d7ae52ac01e..de56d4160a7 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,32 @@
12012-07-10 Paul Eggert <eggert@cs.ucla.edu> 12012-07-10 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 EMACS_TIME simplification (Bug#11875).
4 This replaces macros (which typically do not work in GDB)
5 with functions, typedefs and enums, making the code easier to debug.
6 The functional style also makes code easier to read and maintain.
7 * systime.h: Include <sys/time.h> on all hosts, not just if
8 WINDOWSNT, since 'struct timeval' is needed in general.
9 (EMACS_TIME): Now a typedef, not a macro.
10 (EMACS_TIME_RESOLUTION, LOG10_EMACS_TIME_RESOLUTION): Now constants,
11 not macros.
12 (EMACS_SECS, EMACS_NSECS, EMACS_TIME_SIGN, EMACS_TIME_VALID_P)
13 (EMACS_TIME_FROM_DOUBLE, EMACS_TIME_TO_DOUBLE, EMACS_TIME_EQ)
14 (EMACS_TIME_NE, EMACS_TIME_GT, EMACS_TIME_GE, EMACS_TIME_LT)
15 (EMACS_TIME_LE): Now functions, not macros.
16 (EMACS_SET_SECS, EMACS_SET_NSECS, EMACS_SET_SECS_NSECS)
17 (EMACS_SET_USECS, EMACS_SET_SECS_USECS): Remove these macros,
18 which are not functions. All uses rewritten to use:
19 (make_emacs_time): New function.
20 (EMACS_SECS_ADDR, EMACS_SET_INVALID_TIME, EMACS_GET_TIME)
21 (EMACS_ADD_TIME, EMACS_SUB_TIME): Remove these macros, which are
22 not functions. All uses rewritten to use the following, respectively:
23 (emacs_secs_addr, invalid_emacs_time, get_emacs_time)
24 (add_emacs_time, sub_emacs_time): New functions.
25 * atimer.c: Don't include <sys/time.h>, as "systime.h" does this.
26 * fileio.c (Fcopy_file):
27 * xterm.c (XTflash): Get the current time closer to when it's used.
28 * makefile.w32-in ($(BLD)/atimer.$(O)): Update dependencies.
29
3 * bytecode.c (targets): Suppress -Woverride-init warnings. 30 * bytecode.c (targets): Suppress -Woverride-init warnings.
4 31
5 Simplify by avoiding confusing use of strncpy etc. 32 Simplify by avoiding confusing use of strncpy etc.
diff --git a/src/alloc.c b/src/alloc.c
index 52d683a1b67..89f2c5dbed1 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -5393,7 +5393,7 @@ See Info node `(elisp)Garbage Collection'. */)
5393 int message_p; 5393 int message_p;
5394 Lisp_Object total[8]; 5394 Lisp_Object total[8];
5395 ptrdiff_t count = SPECPDL_INDEX (); 5395 ptrdiff_t count = SPECPDL_INDEX ();
5396 EMACS_TIME t1, t2, t3; 5396 EMACS_TIME t1;
5397 5397
5398 if (abort_on_gc) 5398 if (abort_on_gc)
5399 abort (); 5399 abort ();
@@ -5442,7 +5442,7 @@ See Info node `(elisp)Garbage Collection'. */)
5442 } 5442 }
5443 } 5443 }
5444 5444
5445 EMACS_GET_TIME (t1); 5445 t1 = current_emacs_time ();
5446 5446
5447 /* In case user calls debug_print during GC, 5447 /* In case user calls debug_print during GC,
5448 don't let that cause a recursive GC. */ 5448 don't let that cause a recursive GC. */
@@ -5696,8 +5696,8 @@ See Info node `(elisp)Garbage Collection'. */)
5696 /* Accumulate statistics. */ 5696 /* Accumulate statistics. */
5697 if (FLOATP (Vgc_elapsed)) 5697 if (FLOATP (Vgc_elapsed))
5698 { 5698 {
5699 EMACS_GET_TIME (t2); 5699 EMACS_TIME t2 = current_emacs_time ();
5700 EMACS_SUB_TIME (t3, t2, t1); 5700 EMACS_TIME t3 = sub_emacs_time (t2, t1);
5701 Vgc_elapsed = make_float (XFLOAT_DATA (Vgc_elapsed) 5701 Vgc_elapsed = make_float (XFLOAT_DATA (Vgc_elapsed)
5702 + EMACS_TIME_TO_DOUBLE (t3)); 5702 + EMACS_TIME_TO_DOUBLE (t3));
5703 } 5703 }
diff --git a/src/atimer.c b/src/atimer.c
index 39ac3e826bb..d67e1375f9a 100644
--- a/src/atimer.c
+++ b/src/atimer.c
@@ -26,7 +26,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26#include "blockinput.h" 26#include "blockinput.h"
27#include "atimer.h" 27#include "atimer.h"
28#include <unistd.h> 28#include <unistd.h>
29#include <sys/time.h>
30 29
31/* Free-list of atimer structures. */ 30/* Free-list of atimer structures. */
32 31
@@ -93,10 +92,7 @@ start_atimer (enum atimer_type type, EMACS_TIME timestamp, atimer_callback fn,
93#ifndef HAVE_SETITIMER 92#ifndef HAVE_SETITIMER
94 if (EMACS_NSECS (timestamp) != 0 93 if (EMACS_NSECS (timestamp) != 0
95 && EMACS_SECS (timestamp) < TYPE_MAXIMUM (time_t)) 94 && EMACS_SECS (timestamp) < TYPE_MAXIMUM (time_t))
96 { 95 timestamp = make_emacs_time (EMACS_SECS (timestamp) + 1, 0);
97 EMACS_SET_USECS (timestamp, 0);
98 EMACS_SET_SECS (timestamp, EMACS_SECS (timestamp) + 1);
99 }
100#endif /* not HAVE_SETITIMER */ 96#endif /* not HAVE_SETITIMER */
101 97
102 /* Get an atimer structure from the free-list, or allocate 98 /* Get an atimer structure from the free-list, or allocate
@@ -125,13 +121,11 @@ start_atimer (enum atimer_type type, EMACS_TIME timestamp, atimer_callback fn,
125 break; 121 break;
126 122
127 case ATIMER_RELATIVE: 123 case ATIMER_RELATIVE:
128 EMACS_GET_TIME (t->expiration); 124 t->expiration = add_emacs_time (current_emacs_time (), timestamp);
129 EMACS_ADD_TIME (t->expiration, t->expiration, timestamp);
130 break; 125 break;
131 126
132 case ATIMER_CONTINUOUS: 127 case ATIMER_CONTINUOUS:
133 EMACS_GET_TIME (t->expiration); 128 t->expiration = add_emacs_time (current_emacs_time (), timestamp);
134 EMACS_ADD_TIME (t->expiration, t->expiration, timestamp);
135 t->interval = timestamp; 129 t->interval = timestamp;
136 break; 130 break;
137 } 131 }
@@ -285,31 +279,25 @@ set_alarm (void)
285{ 279{
286 if (atimers) 280 if (atimers)
287 { 281 {
288 EMACS_TIME now, timestamp;
289#ifdef HAVE_SETITIMER 282#ifdef HAVE_SETITIMER
290 struct itimerval it; 283 struct itimerval it;
291#endif 284#endif
292 285
293 /* Determine s/us till the next timer is ripe. */ 286 /* Determine s/us till the next timer is ripe. */
294 EMACS_GET_TIME (now); 287 EMACS_TIME now = current_emacs_time ();
295 288
296 /* Don't set the interval to 0; this disables the timer. */ 289 /* Don't set the interval to 0; this disables the timer. */
297 if (EMACS_TIME_LE (atimers->expiration, now)) 290 EMACS_TIME interval = (EMACS_TIME_LE (atimers->expiration, now)
298 { 291 ? make_emacs_time (0, 1000 * 1000)
299 EMACS_SET_SECS (timestamp, 0); 292 : sub_emacs_time (atimers->expiration, now));
300 EMACS_SET_USECS (timestamp, 1000);
301 }
302 else
303 EMACS_SUB_TIME (timestamp, atimers->expiration, now);
304
305 293
306#ifdef HAVE_SETITIMER 294#ifdef HAVE_SETITIMER
307 295
308 memset (&it, 0, sizeof it); 296 memset (&it, 0, sizeof it);
309 it.it_value = make_timeval (timestamp); 297 it.it_value = make_timeval (interval);
310 setitimer (ITIMER_REAL, &it, 0); 298 setitimer (ITIMER_REAL, &it, 0);
311#else /* not HAVE_SETITIMER */ 299#else /* not HAVE_SETITIMER */
312 alarm (max (EMACS_SECS (timestamp), 1)); 300 alarm (max (EMACS_SECS (interval), 1));
313#endif /* not HAVE_SETITIMER */ 301#endif /* not HAVE_SETITIMER */
314 } 302 }
315} 303}
@@ -344,7 +332,7 @@ run_timers (void)
344 332
345 while (atimers 333 while (atimers
346 && (pending_atimers = interrupt_input_blocked) == 0 334 && (pending_atimers = interrupt_input_blocked) == 0
347 && (EMACS_GET_TIME (now), 335 && (now = current_emacs_time (),
348 EMACS_TIME_LE (atimers->expiration, now))) 336 EMACS_TIME_LE (atimers->expiration, now)))
349 { 337 {
350 struct atimer *t; 338 struct atimer *t;
@@ -355,7 +343,7 @@ run_timers (void)
355 343
356 if (t->type == ATIMER_CONTINUOUS) 344 if (t->type == ATIMER_CONTINUOUS)
357 { 345 {
358 EMACS_ADD_TIME (t->expiration, now, t->interval); 346 t->expiration = add_emacs_time (now, t->interval);
359 schedule_atimer (t); 347 schedule_atimer (t);
360 } 348 }
361 else 349 else
diff --git a/src/buffer.c b/src/buffer.c
index f06a2a5ea0c..b8c81a10d54 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -705,7 +705,7 @@ reset_buffer (register struct buffer *b)
705 BVAR (b, filename) = Qnil; 705 BVAR (b, filename) = Qnil;
706 BVAR (b, file_truename) = Qnil; 706 BVAR (b, file_truename) = Qnil;
707 BVAR (b, directory) = (current_buffer) ? BVAR (current_buffer, directory) : Qnil; 707 BVAR (b, directory) = (current_buffer) ? BVAR (current_buffer, directory) : Qnil;
708 EMACS_SET_SECS_NSECS (b->modtime, 0, UNKNOWN_MODTIME_NSECS); 708 b->modtime = make_emacs_time (0, UNKNOWN_MODTIME_NSECS);
709 b->modtime_size = -1; 709 b->modtime_size = -1;
710 XSETFASTINT (BVAR (b, save_length), 0); 710 XSETFASTINT (BVAR (b, save_length), 0);
711 b->last_window_start = 1; 711 b->last_window_start = 1;
diff --git a/src/dispnew.c b/src/dispnew.c
index 0d34147e035..c149baec507 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -3191,7 +3191,6 @@ update_frame (struct frame *f, int force_p, int inhibit_hairy_id_p)
3191 force_p = 1; 3191 force_p = 1;
3192 else if (!force_p && NUMBERP (Vredisplay_preemption_period)) 3192 else if (!force_p && NUMBERP (Vredisplay_preemption_period))
3193 { 3193 {
3194 EMACS_TIME tm;
3195 double p = XFLOATINT (Vredisplay_preemption_period); 3194 double p = XFLOATINT (Vredisplay_preemption_period);
3196 3195
3197 if (detect_input_pending_ignore_squeezables ()) 3196 if (detect_input_pending_ignore_squeezables ())
@@ -3200,9 +3199,9 @@ update_frame (struct frame *f, int force_p, int inhibit_hairy_id_p)
3200 goto do_pause; 3199 goto do_pause;
3201 } 3200 }
3202 3201
3203 EMACS_GET_TIME (tm);
3204 preemption_period = EMACS_TIME_FROM_DOUBLE (p); 3202 preemption_period = EMACS_TIME_FROM_DOUBLE (p);
3205 EMACS_ADD_TIME (preemption_next_check, tm, preemption_period); 3203 preemption_next_check = add_emacs_time (current_emacs_time (),
3204 preemption_period);
3206 } 3205 }
3207 3206
3208 if (FRAME_WINDOW_P (f)) 3207 if (FRAME_WINDOW_P (f))
@@ -3344,12 +3343,10 @@ update_single_window (struct window *w, int force_p)
3344 force_p = 1; 3343 force_p = 1;
3345 else if (!force_p && NUMBERP (Vredisplay_preemption_period)) 3344 else if (!force_p && NUMBERP (Vredisplay_preemption_period))
3346 { 3345 {
3347 EMACS_TIME tm;
3348 double p = XFLOATINT (Vredisplay_preemption_period); 3346 double p = XFLOATINT (Vredisplay_preemption_period);
3349
3350 EMACS_GET_TIME (tm);
3351 preemption_period = EMACS_TIME_FROM_DOUBLE (p); 3347 preemption_period = EMACS_TIME_FROM_DOUBLE (p);
3352 EMACS_ADD_TIME (preemption_next_check, tm, preemption_period); 3348 preemption_next_check = add_emacs_time (current_emacs_time (),
3349 preemption_period);
3353 } 3350 }
3354 3351
3355 /* Update W. */ 3352 /* Update W. */
@@ -3596,11 +3593,11 @@ update_window (struct window *w, int force_p)
3596#if PERIODIC_PREEMPTION_CHECKING 3593#if PERIODIC_PREEMPTION_CHECKING
3597 if (!force_p) 3594 if (!force_p)
3598 { 3595 {
3599 EMACS_TIME tm; 3596 EMACS_TIME tm = current_emacs_time ();
3600 EMACS_GET_TIME (tm);
3601 if (EMACS_TIME_LT (preemption_next_check, tm)) 3597 if (EMACS_TIME_LT (preemption_next_check, tm))
3602 { 3598 {
3603 EMACS_ADD_TIME (preemption_next_check, tm, preemption_period); 3599 preemption_next_check = add_emacs_time (tm,
3600 preemption_period);
3604 if (detect_input_pending_ignore_squeezables ()) 3601 if (detect_input_pending_ignore_squeezables ())
3605 break; 3602 break;
3606 } 3603 }
@@ -4701,11 +4698,10 @@ update_frame_1 (struct frame *f, int force_p, int inhibit_id_p)
4701#if PERIODIC_PREEMPTION_CHECKING 4698#if PERIODIC_PREEMPTION_CHECKING
4702 if (!force_p) 4699 if (!force_p)
4703 { 4700 {
4704 EMACS_TIME tm; 4701 EMACS_TIME tm = current_emacs_time ();
4705 EMACS_GET_TIME (tm);
4706 if (EMACS_TIME_LT (preemption_next_check, tm)) 4702 if (EMACS_TIME_LT (preemption_next_check, tm))
4707 { 4703 {
4708 EMACS_ADD_TIME (preemption_next_check, tm, preemption_period); 4704 preemption_next_check = add_emacs_time (tm, preemption_period);
4709 if (detect_input_pending_ignore_squeezables ()) 4705 if (detect_input_pending_ignore_squeezables ())
4710 break; 4706 break;
4711 } 4707 }
diff --git a/src/editfns.c b/src/editfns.c
index e48097ab3a6..32d11faa216 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -1408,10 +1408,7 @@ least significant 16 bits. USEC and PSEC are the microsecond and
1408picosecond counts. */) 1408picosecond counts. */)
1409 (void) 1409 (void)
1410{ 1410{
1411 EMACS_TIME t; 1411 return make_lisp_time (current_emacs_time ());
1412
1413 EMACS_GET_TIME (t);
1414 return make_lisp_time (t);
1415} 1412}
1416 1413
1417DEFUN ("get-internal-run-time", Fget_internal_run_time, Sget_internal_run_time, 1414DEFUN ("get-internal-run-time", Fget_internal_run_time, Sget_internal_run_time,
@@ -1428,7 +1425,6 @@ does the same thing as `current-time'. */)
1428 struct rusage usage; 1425 struct rusage usage;
1429 time_t secs; 1426 time_t secs;
1430 int usecs; 1427 int usecs;
1431 EMACS_TIME t;
1432 1428
1433 if (getrusage (RUSAGE_SELF, &usage) < 0) 1429 if (getrusage (RUSAGE_SELF, &usage) < 0)
1434 /* This shouldn't happen. What action is appropriate? */ 1430 /* This shouldn't happen. What action is appropriate? */
@@ -1442,8 +1438,7 @@ does the same thing as `current-time'. */)
1442 usecs -= 1000000; 1438 usecs -= 1000000;
1443 secs++; 1439 secs++;
1444 } 1440 }
1445 EMACS_SET_SECS_USECS (t, secs, usecs); 1441 return make_lisp_time (make_emacs_time (secs, usecs * 1000));
1446 return make_lisp_time (t);
1447#else /* ! HAVE_GETRUSAGE */ 1442#else /* ! HAVE_GETRUSAGE */
1448#ifdef WINDOWSNT 1443#ifdef WINDOWSNT
1449 return w32_get_internal_run_time (); 1444 return w32_get_internal_run_time ();
@@ -1560,8 +1555,7 @@ decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec,
1560 /* Return the greatest representable time that is not greater 1555 /* Return the greatest representable time that is not greater
1561 than the requested time. */ 1556 than the requested time. */
1562 time_t sec = hi; 1557 time_t sec = hi;
1563 EMACS_SET_SECS_NSECS (*result, (sec << 16) + lo, 1558 *result = make_emacs_time ((sec << 16) + lo, us * 1000 + ps / 1000);
1564 us * 1000 + ps / 1000);
1565 } 1559 }
1566 else 1560 else
1567 { 1561 {
@@ -1587,7 +1581,7 @@ lisp_time_argument (Lisp_Object specified_time)
1587{ 1581{
1588 EMACS_TIME t; 1582 EMACS_TIME t;
1589 if (NILP (specified_time)) 1583 if (NILP (specified_time))
1590 EMACS_GET_TIME (t); 1584 t = current_emacs_time ();
1591 else 1585 else
1592 { 1586 {
1593 Lisp_Object high, low, usec, psec; 1587 Lisp_Object high, low, usec, psec;
@@ -1635,8 +1629,7 @@ or (if you need time as a string) `format-time-string'. */)
1635 double t; 1629 double t;
1636 if (NILP (specified_time)) 1630 if (NILP (specified_time))
1637 { 1631 {
1638 EMACS_TIME now; 1632 EMACS_TIME now = current_emacs_time ();
1639 EMACS_GET_TIME (now);
1640 t = EMACS_SECS (now) + EMACS_NSECS (now) / 1e9; 1633 t = EMACS_SECS (now) + EMACS_NSECS (now) / 1e9;
1641 } 1634 }
1642 else 1635 else
@@ -1780,11 +1773,12 @@ format_time_string (char const *format, ptrdiff_t formatlen,
1780 1773
1781 while (1) 1774 while (1)
1782 { 1775 {
1776 time_t *taddr = emacs_secs_addr (&t);
1783 BLOCK_INPUT; 1777 BLOCK_INPUT;
1784 1778
1785 synchronize_system_time_locale (); 1779 synchronize_system_time_locale ();
1786 1780
1787 tm = ut ? gmtime (EMACS_SECS_ADDR (t)) : localtime (EMACS_SECS_ADDR (t)); 1781 tm = ut ? gmtime (taddr) : localtime (taddr);
1788 if (! tm) 1782 if (! tm)
1789 { 1783 {
1790 UNBLOCK_INPUT; 1784 UNBLOCK_INPUT;
@@ -2065,10 +2059,10 @@ the data it can't find. */)
2065 Lisp_Object zone_offset, zone_name; 2059 Lisp_Object zone_offset, zone_name;
2066 2060
2067 zone_offset = Qnil; 2061 zone_offset = Qnil;
2068 EMACS_SET_SECS_NSECS (value, lisp_seconds_argument (specified_time), 0); 2062 value = make_emacs_time (lisp_seconds_argument (specified_time), 0);
2069 zone_name = format_time_string ("%Z", sizeof "%Z" - 1, value, 0, &localtm); 2063 zone_name = format_time_string ("%Z", sizeof "%Z" - 1, value, 0, &localtm);
2070 BLOCK_INPUT; 2064 BLOCK_INPUT;
2071 t = gmtime (EMACS_SECS_ADDR (value)); 2065 t = gmtime (emacs_secs_addr (&value));
2072 if (t) 2066 if (t)
2073 offset = tm_diff (&localtm, t); 2067 offset = tm_diff (&localtm, t);
2074 UNBLOCK_INPUT; 2068 UNBLOCK_INPUT;
diff --git a/src/fileio.c b/src/fileio.c
index eccb1fbb559..2b55b6f6bd1 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -1927,12 +1927,12 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */)
1927 DWORD attributes; 1927 DWORD attributes;
1928 char * filename; 1928 char * filename;
1929 1929
1930 EMACS_GET_TIME (now);
1931 filename = SDATA (encoded_newname); 1930 filename = SDATA (encoded_newname);
1932 1931
1933 /* Ensure file is writable while its modified time is set. */ 1932 /* Ensure file is writable while its modified time is set. */
1934 attributes = GetFileAttributes (filename); 1933 attributes = GetFileAttributes (filename);
1935 SetFileAttributes (filename, attributes & ~FILE_ATTRIBUTE_READONLY); 1934 SetFileAttributes (filename, attributes & ~FILE_ATTRIBUTE_READONLY);
1935 now = current_emacs_time ();
1936 if (set_file_times (-1, filename, now, now)) 1936 if (set_file_times (-1, filename, now, now))
1937 { 1937 {
1938 /* Restore original attributes. */ 1938 /* Restore original attributes. */
@@ -3219,12 +3219,10 @@ emacs_lseek (int fd, EMACS_INT offset, int whence)
3219static EMACS_TIME 3219static EMACS_TIME
3220time_error_value (int errnum) 3220time_error_value (int errnum)
3221{ 3221{
3222 EMACS_TIME t;
3223 int ns = (errnum == ENOENT || errnum == EACCES || errnum == ENOTDIR 3222 int ns = (errnum == ENOENT || errnum == EACCES || errnum == ENOTDIR
3224 ? NONEXISTENT_MODTIME_NSECS 3223 ? NONEXISTENT_MODTIME_NSECS
3225 : UNKNOWN_MODTIME_NSECS); 3224 : UNKNOWN_MODTIME_NSECS);
3226 EMACS_SET_SECS_NSECS (t, 0, ns); 3225 return make_emacs_time (0, ns);
3227 return t;
3228} 3226}
3229 3227
3230DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents, 3228DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents,
@@ -5084,7 +5082,7 @@ See Info node `(elisp)Modification Time' for more details. */)
5084 struct stat st; 5082 struct stat st;
5085 Lisp_Object handler; 5083 Lisp_Object handler;
5086 Lisp_Object filename; 5084 Lisp_Object filename;
5087 EMACS_TIME mtime, diff, one_second; 5085 EMACS_TIME mtime, diff;
5088 5086
5089 if (NILP (buf)) 5087 if (NILP (buf))
5090 b = current_buffer; 5088 b = current_buffer;
@@ -5112,11 +5110,10 @@ See Info node `(elisp)Modification Time' for more details. */)
5112 if ((EMACS_TIME_EQ (mtime, b->modtime) 5110 if ((EMACS_TIME_EQ (mtime, b->modtime)
5113 /* If both exist, accept them if they are off by one second. */ 5111 /* If both exist, accept them if they are off by one second. */
5114 || (EMACS_TIME_VALID_P (mtime) && EMACS_TIME_VALID_P (b->modtime) 5112 || (EMACS_TIME_VALID_P (mtime) && EMACS_TIME_VALID_P (b->modtime)
5115 && ((EMACS_TIME_LT (mtime, b->modtime) 5113 && ((diff = (EMACS_TIME_LT (mtime, b->modtime)
5116 ? EMACS_SUB_TIME (diff, b->modtime, mtime) 5114 ? sub_emacs_time (b->modtime, mtime)
5117 : EMACS_SUB_TIME (diff, mtime, b->modtime)), 5115 : sub_emacs_time (mtime, b->modtime))),
5118 EMACS_SET_SECS_NSECS (one_second, 1, 0), 5116 EMACS_TIME_LE (diff, make_emacs_time (1, 0)))))
5119 EMACS_TIME_LE (diff, one_second))))
5120 && (st.st_size == b->modtime_size 5117 && (st.st_size == b->modtime_size
5121 || b->modtime_size < 0)) 5118 || b->modtime_size < 0))
5122 return Qt; 5119 return Qt;
@@ -5129,7 +5126,7 @@ DEFUN ("clear-visited-file-modtime", Fclear_visited_file_modtime,
5129Next attempt to save will certainly not complain of a discrepancy. */) 5126Next attempt to save will certainly not complain of a discrepancy. */)
5130 (void) 5127 (void)
5131{ 5128{
5132 EMACS_SET_SECS_NSECS (current_buffer->modtime, 0, UNKNOWN_MODTIME_NSECS); 5129 current_buffer->modtime = make_emacs_time (0, UNKNOWN_MODTIME_NSECS);
5133 current_buffer->modtime_size = -1; 5130 current_buffer->modtime_size = -1;
5134 return Qnil; 5131 return Qnil;
5135} 5132}
@@ -5428,9 +5425,8 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */)
5428 || NILP (Ffind_file_name_handler (BVAR (b, auto_save_file_name), 5425 || NILP (Ffind_file_name_handler (BVAR (b, auto_save_file_name),
5429 Qwrite_region)))) 5426 Qwrite_region))))
5430 { 5427 {
5431 EMACS_TIME before_time, after_time; 5428 EMACS_TIME before_time = current_emacs_time ();
5432 5429 EMACS_TIME after_time;
5433 EMACS_GET_TIME (before_time);
5434 5430
5435 /* If we had a failure, don't try again for 20 minutes. */ 5431 /* If we had a failure, don't try again for 20 minutes. */
5436 if (b->auto_save_failure_time > 0 5432 if (b->auto_save_failure_time > 0
@@ -5467,7 +5463,7 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */)
5467 XSETFASTINT (BVAR (current_buffer, save_length), Z - BEG); 5463 XSETFASTINT (BVAR (current_buffer, save_length), Z - BEG);
5468 set_buffer_internal (old); 5464 set_buffer_internal (old);
5469 5465
5470 EMACS_GET_TIME (after_time); 5466 after_time = current_emacs_time ();
5471 5467
5472 /* If auto-save took more than 60 seconds, 5468 /* If auto-save took more than 60 seconds,
5473 assume it was an NFS failure that got a timeout. */ 5469 assume it was an NFS failure that got a timeout. */
diff --git a/src/fns.c b/src/fns.c
index c30c85f7b45..a42a1530906 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -78,8 +78,7 @@ Other values of LIMIT are ignored. */)
78 78
79 if (EQ (limit, Qt)) 79 if (EQ (limit, Qt))
80 { 80 {
81 EMACS_TIME t; 81 EMACS_TIME t = current_emacs_time ();
82 EMACS_GET_TIME (t);
83 seed_random (getpid () ^ EMACS_SECS (t) ^ EMACS_NSECS (t)); 82 seed_random (getpid () ^ EMACS_SECS (t) ^ EMACS_NSECS (t));
84 } 83 }
85 84
diff --git a/src/image.c b/src/image.c
index b4ad329bacb..88d2f36cda9 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1061,7 +1061,7 @@ void
1061prepare_image_for_display (struct frame *f, struct image *img) 1061prepare_image_for_display (struct frame *f, struct image *img)
1062{ 1062{
1063 /* We're about to display IMG, so set its timestamp to `now'. */ 1063 /* We're about to display IMG, so set its timestamp to `now'. */
1064 EMACS_GET_TIME (img->timestamp); 1064 img->timestamp = current_emacs_time ();
1065 1065
1066 /* If IMG doesn't have a pixmap yet, load it now, using the image 1066 /* If IMG doesn't have a pixmap yet, load it now, using the image
1067 type dependent loader function. */ 1067 type dependent loader function. */
@@ -1520,8 +1520,8 @@ clear_image_cache (struct frame *f, Lisp_Object filter)
1520 delay = 1600 * delay / nimages / nimages; 1520 delay = 1600 * delay / nimages / nimages;
1521 delay = max (delay, 1); 1521 delay = max (delay, 1);
1522 1522
1523 EMACS_GET_TIME (t); 1523 t = current_emacs_time ();
1524 EMACS_SUB_TIME (old, t, EMACS_TIME_FROM_DOUBLE (delay)); 1524 old = sub_emacs_time (t, EMACS_TIME_FROM_DOUBLE (delay));
1525 1525
1526 for (i = 0; i < c->used; ++i) 1526 for (i = 0; i < c->used; ++i)
1527 { 1527 {
@@ -1792,7 +1792,7 @@ lookup_image (struct frame *f, Lisp_Object spec)
1792 } 1792 }
1793 1793
1794 /* We're using IMG, so set its timestamp to `now'. */ 1794 /* We're using IMG, so set its timestamp to `now'. */
1795 EMACS_GET_TIME (img->timestamp); 1795 img->timestamp = current_emacs_time ();
1796 1796
1797 /* Value is the image id. */ 1797 /* Value is the image id. */
1798 return img->id; 1798 return img->id;
diff --git a/src/keyboard.c b/src/keyboard.c
index b34d3c470a5..1ef4ac84d0c 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -2017,12 +2017,11 @@ start_polling (void)
2017 || EMACS_SECS (poll_timer->interval) != polling_period) 2017 || EMACS_SECS (poll_timer->interval) != polling_period)
2018 { 2018 {
2019 time_t period = max (1, min (polling_period, TYPE_MAXIMUM (time_t))); 2019 time_t period = max (1, min (polling_period, TYPE_MAXIMUM (time_t)));
2020 EMACS_TIME interval; 2020 EMACS_TIME interval = make_emacs_time (period, 0);
2021 2021
2022 if (poll_timer) 2022 if (poll_timer)
2023 cancel_atimer (poll_timer); 2023 cancel_atimer (poll_timer);
2024 2024
2025 EMACS_SET_SECS_USECS (interval, period, 0);
2026 poll_timer = start_atimer (ATIMER_CONTINUOUS, interval, 2025 poll_timer = start_atimer (ATIMER_CONTINUOUS, interval,
2027 poll_for_input, NULL); 2026 poll_for_input, NULL);
2028 } 2027 }
@@ -2786,13 +2785,8 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps,
2786 { 2785 {
2787 KBOARD *kb IF_LINT (= NULL); 2786 KBOARD *kb IF_LINT (= NULL);
2788 2787
2789 if (end_time) 2788 if (end_time && EMACS_TIME_LE (*end_time, current_emacs_time ()))
2790 { 2789 goto exit;
2791 EMACS_TIME now;
2792 EMACS_GET_TIME (now);
2793 if (EMACS_TIME_GE (now, *end_time))
2794 goto exit;
2795 }
2796 2790
2797 /* Actually read a character, waiting if necessary. */ 2791 /* Actually read a character, waiting if necessary. */
2798 save_getcjmp (save_jump); 2792 save_getcjmp (save_jump);
@@ -3847,13 +3841,12 @@ kbd_buffer_get_event (KBOARD **kbp,
3847#endif 3841#endif
3848 if (end_time) 3842 if (end_time)
3849 { 3843 {
3850 EMACS_TIME duration; 3844 EMACS_TIME now = current_emacs_time ();
3851 EMACS_GET_TIME (duration); 3845 if (EMACS_TIME_LE (*end_time, now))
3852 if (EMACS_TIME_GE (duration, *end_time))
3853 return Qnil; /* Finished waiting. */ 3846 return Qnil; /* Finished waiting. */
3854 else 3847 else
3855 { 3848 {
3856 EMACS_SUB_TIME (duration, *end_time, duration); 3849 EMACS_TIME duration = sub_emacs_time (*end_time, now);
3857 wait_reading_process_output (min (EMACS_SECS (duration), 3850 wait_reading_process_output (min (EMACS_SECS (duration),
3858 WAIT_READING_MAX), 3851 WAIT_READING_MAX),
3859 EMACS_NSECS (duration), 3852 EMACS_NSECS (duration),
@@ -4256,8 +4249,7 @@ timer_start_idle (void)
4256 if (EMACS_TIME_VALID_P (timer_idleness_start_time)) 4249 if (EMACS_TIME_VALID_P (timer_idleness_start_time))
4257 return; 4250 return;
4258 4251
4259 EMACS_GET_TIME (timer_idleness_start_time); 4252 timer_idleness_start_time = current_emacs_time ();
4260
4261 timer_last_idleness_start_time = timer_idleness_start_time; 4253 timer_last_idleness_start_time = timer_idleness_start_time;
4262 4254
4263 /* Mark all idle-time timers as once again candidates for running. */ 4255 /* Mark all idle-time timers as once again candidates for running. */
@@ -4278,7 +4270,7 @@ timer_start_idle (void)
4278static void 4270static void
4279timer_stop_idle (void) 4271timer_stop_idle (void)
4280{ 4272{
4281 EMACS_SET_INVALID_TIME (timer_idleness_start_time); 4273 timer_idleness_start_time = invalid_emacs_time ();
4282} 4274}
4283 4275
4284/* Resume idle timer from last idle start time. */ 4276/* Resume idle timer from last idle start time. */
@@ -4339,7 +4331,7 @@ timer_check_2 (void)
4339 Lisp_Object timers, idle_timers, chosen_timer; 4331 Lisp_Object timers, idle_timers, chosen_timer;
4340 struct gcpro gcpro1, gcpro2, gcpro3; 4332 struct gcpro gcpro1, gcpro2, gcpro3;
4341 4333
4342 EMACS_SET_INVALID_TIME (nexttime); 4334 nexttime = invalid_emacs_time ();
4343 4335
4344 /* Always consider the ordinary timers. */ 4336 /* Always consider the ordinary timers. */
4345 timers = Vtimer_list; 4337 timers = Vtimer_list;
@@ -4361,11 +4353,10 @@ timer_check_2 (void)
4361 4353
4362 if (CONSP (timers) || CONSP (idle_timers)) 4354 if (CONSP (timers) || CONSP (idle_timers))
4363 { 4355 {
4364 EMACS_GET_TIME (now); 4356 now = current_emacs_time ();
4365 if (EMACS_TIME_VALID_P (timer_idleness_start_time)) 4357 idleness_now = (EMACS_TIME_VALID_P (timer_idleness_start_time)
4366 EMACS_SUB_TIME (idleness_now, now, timer_idleness_start_time); 4358 ? sub_emacs_time (now, timer_idleness_start_time)
4367 else 4359 : make_emacs_time (0, 0));
4368 EMACS_SET_SECS_NSECS (idleness_now, 0, 0);
4369 } 4360 }
4370 4361
4371 while (CONSP (timers) || CONSP (idle_timers)) 4362 while (CONSP (timers) || CONSP (idle_timers))
@@ -4374,12 +4365,10 @@ timer_check_2 (void)
4374 Lisp_Object timer = Qnil, idle_timer = Qnil; 4365 Lisp_Object timer = Qnil, idle_timer = Qnil;
4375 EMACS_TIME timer_time, idle_timer_time; 4366 EMACS_TIME timer_time, idle_timer_time;
4376 EMACS_TIME difference; 4367 EMACS_TIME difference;
4377 EMACS_TIME timer_difference, idle_timer_difference; 4368 EMACS_TIME timer_difference = invalid_emacs_time ();
4369 EMACS_TIME idle_timer_difference = invalid_emacs_time ();
4378 int ripe, timer_ripe = 0, idle_timer_ripe = 0; 4370 int ripe, timer_ripe = 0, idle_timer_ripe = 0;
4379 4371
4380 EMACS_SET_INVALID_TIME (timer_difference);
4381 EMACS_SET_INVALID_TIME (idle_timer_difference);
4382
4383 /* Set TIMER and TIMER_DIFFERENCE 4372 /* Set TIMER and TIMER_DIFFERENCE
4384 based on the next ordinary timer. 4373 based on the next ordinary timer.
4385 TIMER_DIFFERENCE is the distance in time from NOW to when 4374 TIMER_DIFFERENCE is the distance in time from NOW to when
@@ -4395,10 +4384,9 @@ timer_check_2 (void)
4395 } 4384 }
4396 4385
4397 timer_ripe = EMACS_TIME_LE (timer_time, now); 4386 timer_ripe = EMACS_TIME_LE (timer_time, now);
4398 if (timer_ripe) 4387 timer_difference = (timer_ripe
4399 EMACS_SUB_TIME (timer_difference, now, timer_time); 4388 ? sub_emacs_time (now, timer_time)
4400 else 4389 : sub_emacs_time (timer_time, now));
4401 EMACS_SUB_TIME (timer_difference, timer_time, now);
4402 } 4390 }
4403 4391
4404 /* Likewise for IDLE_TIMER and IDLE_TIMER_DIFFERENCE 4392 /* Likewise for IDLE_TIMER and IDLE_TIMER_DIFFERENCE
@@ -4413,12 +4401,10 @@ timer_check_2 (void)
4413 } 4401 }
4414 4402
4415 idle_timer_ripe = EMACS_TIME_LE (idle_timer_time, idleness_now); 4403 idle_timer_ripe = EMACS_TIME_LE (idle_timer_time, idleness_now);
4416 if (idle_timer_ripe) 4404 idle_timer_difference =
4417 EMACS_SUB_TIME (idle_timer_difference, 4405 (idle_timer_ripe
4418 idleness_now, idle_timer_time); 4406 ? sub_emacs_time (idleness_now, idle_timer_time)
4419 else 4407 : sub_emacs_time (idle_timer_time, idleness_now));
4420 EMACS_SUB_TIME (idle_timer_difference,
4421 idle_timer_time, idleness_now);
4422 } 4408 }
4423 4409
4424 /* Decide which timer is the next timer, 4410 /* Decide which timer is the next timer,
@@ -4474,8 +4460,7 @@ timer_check_2 (void)
4474 return 0 to indicate that. */ 4460 return 0 to indicate that. */
4475 } 4461 }
4476 4462
4477 EMACS_SET_SECS (nexttime, 0); 4463 nexttime = make_emacs_time (0, 0);
4478 EMACS_SET_USECS (nexttime, 0);
4479 } 4464 }
4480 else 4465 else
4481 /* When we encounter a timer that is still waiting, 4466 /* When we encounter a timer that is still waiting,
@@ -4527,14 +4512,8 @@ NSEC is a multiple of the system clock resolution. */)
4527 (void) 4512 (void)
4528{ 4513{
4529 if (EMACS_TIME_VALID_P (timer_idleness_start_time)) 4514 if (EMACS_TIME_VALID_P (timer_idleness_start_time))
4530 { 4515 return make_lisp_time (sub_emacs_time (current_emacs_time (),
4531 EMACS_TIME now, idleness_now; 4516 timer_idleness_start_time));
4532
4533 EMACS_GET_TIME (now);
4534 EMACS_SUB_TIME (idleness_now, now, timer_idleness_start_time);
4535
4536 return make_lisp_time (idleness_now);
4537 }
4538 4517
4539 return Qnil; 4518 return Qnil;
4540} 4519}
@@ -7224,7 +7203,7 @@ input_available_signal (int signo)
7224#endif 7203#endif
7225 7204
7226 if (input_available_clear_time) 7205 if (input_available_clear_time)
7227 EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); 7206 *input_available_clear_time = make_emacs_time (0, 0);
7228 7207
7229#ifndef SYNC_INPUT 7208#ifndef SYNC_INPUT
7230 handle_async_input (); 7209 handle_async_input ();
@@ -7327,7 +7306,7 @@ handle_user_signal (int sig)
7327 /* Tell wait_reading_process_output that it needs to wake 7306 /* Tell wait_reading_process_output that it needs to wake
7328 up and look around. */ 7307 up and look around. */
7329 if (input_available_clear_time) 7308 if (input_available_clear_time)
7330 EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); 7309 *input_available_clear_time = make_emacs_time (0, 0);
7331 } 7310 }
7332 break; 7311 break;
7333 } 7312 }
@@ -11344,7 +11323,7 @@ init_keyboard (void)
11344 quit_char = Ctl ('g'); 11323 quit_char = Ctl ('g');
11345 Vunread_command_events = Qnil; 11324 Vunread_command_events = Qnil;
11346 unread_command_char = -1; 11325 unread_command_char = -1;
11347 EMACS_SET_INVALID_TIME (timer_idleness_start_time); 11326 timer_idleness_start_time = invalid_emacs_time ();
11348 total_keys = 0; 11327 total_keys = 0;
11349 recent_keys_index = 0; 11328 recent_keys_index = 0;
11350 kbd_fetch_ptr = kbd_buffer; 11329 kbd_fetch_ptr = kbd_buffer;
diff --git a/src/lread.c b/src/lread.c
index 640414b3e91..c0e4a173eeb 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -604,8 +604,7 @@ read_filtered_event (int no_switch_frame, int ascii_required,
604 { 604 {
605 double duration = extract_float (seconds); 605 double duration = extract_float (seconds);
606 EMACS_TIME wait_time = EMACS_TIME_FROM_DOUBLE (duration); 606 EMACS_TIME wait_time = EMACS_TIME_FROM_DOUBLE (duration);
607 EMACS_GET_TIME (end_time); 607 end_time = add_emacs_time (current_emacs_time (), wait_time);
608 EMACS_ADD_TIME (end_time, end_time, wait_time);
609 } 608 }
610 609
611/* Read until we get an acceptable event. */ 610/* Read until we get an acceptable event. */
diff --git a/src/makefile.w32-in b/src/makefile.w32-in
index 5459224eb10..0106616f3c9 100644
--- a/src/makefile.w32-in
+++ b/src/makefile.w32-in
@@ -490,7 +490,6 @@ $(BLD)/alloc.$(O) : \
490$(BLD)/atimer.$(O) : \ 490$(BLD)/atimer.$(O) : \
491 $(SRC)/atimer.c \ 491 $(SRC)/atimer.c \
492 $(SRC)/syssignal.h \ 492 $(SRC)/syssignal.h \
493 $(NT_INC)/sys/time.h \
494 $(NT_INC)/unistd.h \ 493 $(NT_INC)/unistd.h \
495 $(ATIMER_H) \ 494 $(ATIMER_H) \
496 $(BLOCKINPUT_H) \ 495 $(BLOCKINPUT_H) \
diff --git a/src/msdos.c b/src/msdos.c
index e19e4ef8f3a..d75277e3866 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -4138,14 +4138,14 @@ sys_select (int nfds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
4138 EMACS_TIME clnow, cllast, cldiff; 4138 EMACS_TIME clnow, cllast, cldiff;
4139 4139
4140 gettime (&t); 4140 gettime (&t);
4141 EMACS_SET_SECS_NSECS (cllast, t.tv_sec, t.tv_nsec); 4141 cllast = make_emacs_time (t.tv_sec, t.tv_nsec);
4142 4142
4143 while (!check_input || !detect_input_pending ()) 4143 while (!check_input || !detect_input_pending ())
4144 { 4144 {
4145 gettime (&t); 4145 gettime (&t);
4146 EMACS_SET_SECS_NSECS (clnow, t.tv_sec, t.tv_nsec); 4146 clnow = make_emacs_time (t.tv_sec, t.tv_nsec);
4147 EMACS_SUB_TIME (cldiff, clnow, cllast); 4147 cldiff = sub_emacs_time (clnow, cllast);
4148 EMACS_SUB_TIME (*timeout, *timeout, cldiff); 4148 *timeout = sub_emacs_time (*timeout, cldiff);
4149 4149
4150 /* Stop when timeout value crosses zero. */ 4150 /* Stop when timeout value crosses zero. */
4151 if (EMACS_TIME_SIGN (*timeout) <= 0) 4151 if (EMACS_TIME_SIGN (*timeout) <= 0)
diff --git a/src/nsterm.m b/src/nsterm.m
index 0745efc35bd..686b748c14e 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -410,21 +410,16 @@ ns_timeout (int usecs)
410 Blocking timer utility used by ns_ring_bell 410 Blocking timer utility used by ns_ring_bell
411 -------------------------------------------------------------------------- */ 411 -------------------------------------------------------------------------- */
412{ 412{
413 EMACS_TIME wakeup, delay; 413 EMACS_TIME wakeup = add_emacs_time (current_emacs_time (),
414 414 make_emacs_time (0, usecs * 1000));
415 EMACS_GET_TIME (wakeup);
416 EMACS_SET_SECS_USECS (delay, 0, usecs);
417 EMACS_ADD_TIME (wakeup, wakeup, delay);
418 415
419 /* Keep waiting until past the time wakeup. */ 416 /* Keep waiting until past the time wakeup. */
420 while (1) 417 while (1)
421 { 418 {
422 EMACS_TIME timeout; 419 EMACS_TIME now = current_emacs_time ();
423 420 if (EMACS_TIME_LE (wakeup, now))
424 EMACS_GET_TIME (timeout);
425 if (EMACS_TIME_LE (wakeup, timeout))
426 break; 421 break;
427 EMACS_SUB_TIME (timeout, wakeup, timeout); 422 timeout = sub_emacs_time (wakeup, now);
428 423
429 /* Try to wait that long--but we might wake up sooner. */ 424 /* Try to wait that long--but we might wake up sooner. */
430 pselect (0, NULL, NULL, NULL, &timeout, NULL); 425 pselect (0, NULL, NULL, NULL, &timeout, NULL);
diff --git a/src/process.c b/src/process.c
index 79100eb7a2c..98a47eca7ae 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1851,10 +1851,9 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1851 So have an interrupt jar it loose. */ 1851 So have an interrupt jar it loose. */
1852 { 1852 {
1853 struct atimer *timer; 1853 struct atimer *timer;
1854 EMACS_TIME offset; 1854 EMACS_TIME offset = make_emacs_time (1, 0);
1855 1855
1856 stop_polling (); 1856 stop_polling ();
1857 EMACS_SET_SECS_USECS (offset, 1, 0);
1858 timer = start_atimer (ATIMER_RELATIVE, offset, create_process_1, 0); 1857 timer = start_atimer (ATIMER_RELATIVE, offset, create_process_1, 0);
1859 1858
1860 if (forkin >= 0) 1859 if (forkin >= 0)
@@ -4311,9 +4310,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4311 compute the absolute time to return at. */ 4310 compute the absolute time to return at. */
4312 if (time_limit || 0 < nsecs) 4311 if (time_limit || 0 < nsecs)
4313 { 4312 {
4314 EMACS_GET_TIME (end_time); 4313 timeout = make_emacs_time (time_limit, nsecs);
4315 EMACS_SET_SECS_NSECS (timeout, time_limit, nsecs); 4314 end_time = add_emacs_time (current_emacs_time (), timeout);
4316 EMACS_ADD_TIME (end_time, end_time, timeout);
4317 } 4315 }
4318 4316
4319 while (1) 4317 while (1)
@@ -4342,18 +4340,18 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4342 gobble output available now 4340 gobble output available now
4343 but don't wait at all. */ 4341 but don't wait at all. */
4344 4342
4345 EMACS_SET_SECS_USECS (timeout, 0, 0); 4343 timeout = make_emacs_time (0, 0);
4346 } 4344 }
4347 else if (time_limit || 0 < nsecs) 4345 else if (time_limit || 0 < nsecs)
4348 { 4346 {
4349 EMACS_GET_TIME (timeout); 4347 EMACS_TIME now = current_emacs_time ();
4350 if (EMACS_TIME_LE (end_time, timeout)) 4348 if (EMACS_TIME_LE (end_time, now))
4351 break; 4349 break;
4352 EMACS_SUB_TIME (timeout, end_time, timeout); 4350 timeout = sub_emacs_time (end_time, now);
4353 } 4351 }
4354 else 4352 else
4355 { 4353 {
4356 EMACS_SET_SECS_USECS (timeout, 100000, 0); 4354 timeout = make_emacs_time (100000, 0);
4357 } 4355 }
4358 4356
4359 /* Normally we run timers here. 4357 /* Normally we run timers here.
@@ -4438,7 +4436,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4438 Atemp = input_wait_mask; 4436 Atemp = input_wait_mask;
4439 Ctemp = write_mask; 4437 Ctemp = write_mask;
4440 4438
4441 EMACS_SET_SECS_USECS (timeout, 0, 0); 4439 timeout = make_emacs_time (0, 0);
4442 if ((pselect (max (max_process_desc, max_input_desc) + 1, 4440 if ((pselect (max (max_process_desc, max_input_desc) + 1,
4443 &Atemp, 4441 &Atemp,
4444#ifdef NON_BLOCKING_CONNECT 4442#ifdef NON_BLOCKING_CONNECT
@@ -4590,7 +4588,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4590 nsecs = XPROCESS (proc)->read_output_delay; 4588 nsecs = XPROCESS (proc)->read_output_delay;
4591 } 4589 }
4592 } 4590 }
4593 EMACS_SET_SECS_NSECS (timeout, 0, nsecs); 4591 timeout = make_emacs_time (0, nsecs);
4594 process_output_skip = 0; 4592 process_output_skip = 0;
4595 } 4593 }
4596#endif 4594#endif
@@ -6426,7 +6424,7 @@ sigchld_handler (int signo)
6426 /* Tell wait_reading_process_output that it needs to wake up and 6424 /* Tell wait_reading_process_output that it needs to wake up and
6427 look around. */ 6425 look around. */
6428 if (input_available_clear_time) 6426 if (input_available_clear_time)
6429 EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); 6427 *input_available_clear_time = make_emacs_time (0, 0);
6430 } 6428 }
6431 6429
6432 /* There was no asynchronous process found for that pid: we have 6430 /* There was no asynchronous process found for that pid: we have
@@ -6444,7 +6442,7 @@ sigchld_handler (int signo)
6444 /* Tell wait_reading_process_output that it needs to wake up and 6442 /* Tell wait_reading_process_output that it needs to wake up and
6445 look around. */ 6443 look around. */
6446 if (input_available_clear_time) 6444 if (input_available_clear_time)
6447 EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); 6445 *input_available_clear_time = make_emacs_time (0, 0);
6448 } 6446 }
6449 6447
6450 sigchld_end_of_loop: 6448 sigchld_end_of_loop:
@@ -6857,9 +6855,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
6857 /* What does time_limit really mean? */ 6855 /* What does time_limit really mean? */
6858 if (time_limit || 0 < nsecs) 6856 if (time_limit || 0 < nsecs)
6859 { 6857 {
6860 EMACS_GET_TIME (end_time); 6858 timeout = make_emacs_time (time_limit, nsecs);
6861 EMACS_SET_SECS_NSECS (timeout, time_limit, nsecs); 6859 end_time = add_emacs_time (current_emacs_time (), timeout);
6862 EMACS_ADD_TIME (end_time, end_time, timeout);
6863 } 6860 }
6864 6861
6865 /* Turn off periodic alarms (in case they are in use) 6862 /* Turn off periodic alarms (in case they are in use)
@@ -6892,18 +6889,18 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
6892 gobble output available now 6889 gobble output available now
6893 but don't wait at all. */ 6890 but don't wait at all. */
6894 6891
6895 EMACS_SET_SECS_USECS (timeout, 0, 0); 6892 timeout = make_emacs_time (0, 0);
6896 } 6893 }
6897 else if (time_limit || 0 < nsecs) 6894 else if (time_limit || 0 < nsecs)
6898 { 6895 {
6899 EMACS_GET_TIME (timeout); 6896 EMACS_TIME now = current_emacs_time ();
6900 if (EMACS_TIME_LE (end_time, timeout)) 6897 if (EMACS_TIME_LE (end_time, now))
6901 break; 6898 break;
6902 EMACS_SUB_TIME (timeout, end_time, timeout); 6899 timeout = sub_emacs_time (end_time, now);
6903 } 6900 }
6904 else 6901 else
6905 { 6902 {
6906 EMACS_SET_SECS_USECS (timeout, 100000, 0); 6903 timeout = make_emacs_time (100000, 0);
6907 } 6904 }
6908 6905
6909 /* If our caller will not immediately handle keyboard events, 6906 /* If our caller will not immediately handle keyboard events,
diff --git a/src/sysdep.c b/src/sysdep.c
index ed926760414..37dc75529d0 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -2586,7 +2586,6 @@ time_from_jiffies (unsigned long long tval, long hz)
2586 unsigned long long s = tval / hz; 2586 unsigned long long s = tval / hz;
2587 unsigned long long frac = tval % hz; 2587 unsigned long long frac = tval % hz;
2588 int ns; 2588 int ns;
2589 EMACS_TIME t;
2590 2589
2591 if (TYPE_MAXIMUM (time_t) < s) 2590 if (TYPE_MAXIMUM (time_t) < s)
2592 time_overflow (); 2591 time_overflow ();
@@ -2603,8 +2602,7 @@ time_from_jiffies (unsigned long long tval, long hz)
2603 ns = frac / hz_per_ns; 2602 ns = frac / hz_per_ns;
2604 } 2603 }
2605 2604
2606 EMACS_SET_SECS_NSECS (t, s, ns); 2605 return make_emacs_time (s, ns);
2607 return t;
2608} 2606}
2609 2607
2610static Lisp_Object 2608static Lisp_Object
@@ -2618,9 +2616,7 @@ static EMACS_TIME
2618get_up_time (void) 2616get_up_time (void)
2619{ 2617{
2620 FILE *fup; 2618 FILE *fup;
2621 EMACS_TIME up; 2619 EMACS_TIME up = make_emacs_time (0, 0);
2622
2623 EMACS_SET_SECS_NSECS (up, 0, 0);
2624 2620
2625 BLOCK_INPUT; 2621 BLOCK_INPUT;
2626 fup = fopen ("/proc/uptime", "r"); 2622 fup = fopen ("/proc/uptime", "r");
@@ -2649,7 +2645,7 @@ get_up_time (void)
2649 upfrac /= 10; 2645 upfrac /= 10;
2650 upfrac = min (upfrac, EMACS_TIME_RESOLUTION - 1); 2646 upfrac = min (upfrac, EMACS_TIME_RESOLUTION - 1);
2651 } 2647 }
2652 EMACS_SET_SECS_NSECS (up, upsec, upfrac); 2648 up = make_emacs_time (upsec, upfrac);
2653 } 2649 }
2654 fclose (fup); 2650 fclose (fup);
2655 } 2651 }
@@ -2874,15 +2870,15 @@ system_process_attributes (Lisp_Object pid)
2874 attrs = Fcons (Fcons (Qpri, make_number (priority)), attrs); 2870 attrs = Fcons (Fcons (Qpri, make_number (priority)), attrs);
2875 attrs = Fcons (Fcons (Qnice, make_number (niceness)), attrs); 2871 attrs = Fcons (Fcons (Qnice, make_number (niceness)), attrs);
2876 attrs = Fcons (Fcons (Qthcount, make_fixnum_or_float (thcount_eint)), attrs); 2872 attrs = Fcons (Fcons (Qthcount, make_fixnum_or_float (thcount_eint)), attrs);
2877 EMACS_GET_TIME (tnow); 2873 tnow = current_emacs_time ();
2878 telapsed = get_up_time (); 2874 telapsed = get_up_time ();
2879 EMACS_SUB_TIME (tboot, tnow, telapsed); 2875 tboot = sub_emacs_time (tnow, telapsed);
2880 tstart = time_from_jiffies (start, clocks_per_sec); 2876 tstart = time_from_jiffies (start, clocks_per_sec);
2881 EMACS_ADD_TIME (tstart, tboot, tstart); 2877 tstart = add_emacs_time (tboot, tstart);
2882 attrs = Fcons (Fcons (Qstart, make_lisp_time (tstart)), attrs); 2878 attrs = Fcons (Fcons (Qstart, make_lisp_time (tstart)), attrs);
2883 attrs = Fcons (Fcons (Qvsize, make_fixnum_or_float (vsize/1024)), attrs); 2879 attrs = Fcons (Fcons (Qvsize, make_fixnum_or_float (vsize/1024)), attrs);
2884 attrs = Fcons (Fcons (Qrss, make_fixnum_or_float (4*rss)), attrs); 2880 attrs = Fcons (Fcons (Qrss, make_fixnum_or_float (4*rss)), attrs);
2885 EMACS_SUB_TIME (telapsed, tnow, tstart); 2881 telapsed = sub_emacs_time (tnow, tstart);
2886 attrs = Fcons (Fcons (Qetime, make_lisp_time (telapsed)), attrs); 2882 attrs = Fcons (Fcons (Qetime, make_lisp_time (telapsed)), attrs);
2887 us_time = time_from_jiffies (u_time + s_time, clocks_per_sec); 2883 us_time = time_from_jiffies (u_time + s_time, clocks_per_sec);
2888 pcpu = (EMACS_TIME_TO_DOUBLE (us_time) 2884 pcpu = (EMACS_TIME_TO_DOUBLE (us_time)
@@ -3101,9 +3097,7 @@ system_process_attributes (Lisp_Object pid)
3101static EMACS_TIME 3097static EMACS_TIME
3102timeval_to_EMACS_TIME (struct timeval t) 3098timeval_to_EMACS_TIME (struct timeval t)
3103{ 3099{
3104 EMACS_TIME e; 3100 return make_emacs_time (t.tv_sec, t.tv_usec * 1000);
3105 EMACS_SET_SECS_NSECS (e, t.tv_sec, t.tv_usec * 1000);
3106 return e;
3107} 3101}
3108 3102
3109static Lisp_Object 3103static Lisp_Object
@@ -3211,9 +3205,8 @@ system_process_attributes (Lisp_Object pid)
3211 attrs); 3205 attrs);
3212 attrs = Fcons (Fcons (Qstime, make_lisp_timeval (proc.ki_rusage.ru_stime)), 3206 attrs = Fcons (Fcons (Qstime, make_lisp_timeval (proc.ki_rusage.ru_stime)),
3213 attrs); 3207 attrs);
3214 EMACS_ADD_TIME (t, 3208 t = add_emacs_time (timeval_to_EMACS_TIME (proc.ki_rusage.ru_utime),
3215 timeval_to_EMACS_TIME (proc.ki_rusage.ru_utime), 3209 timeval_to_EMACS_TIME (proc.ki_rusage.ru_stime));
3216 timeval_to_EMACS_TIME (proc.ki_rusage.ru_stime));
3217 attrs = Fcons (Fcons (Qtime, make_lisp_time (t)), attrs); 3210 attrs = Fcons (Fcons (Qtime, make_lisp_time (t)), attrs);
3218 3211
3219 attrs = Fcons (Fcons (Qcutime, 3212 attrs = Fcons (Fcons (Qcutime,
@@ -3222,9 +3215,8 @@ system_process_attributes (Lisp_Object pid)
3222 attrs = Fcons (Fcons (Qcstime, 3215 attrs = Fcons (Fcons (Qcstime,
3223 make_lisp_timeval (proc.ki_rusage_ch.ru_utime)), 3216 make_lisp_timeval (proc.ki_rusage_ch.ru_utime)),
3224 attrs); 3217 attrs);
3225 EMACS_ADD_TIME (t, 3218 t = add_emacs_time (timeval_to_EMACS_TIME (proc.ki_rusage_ch.ru_utime),
3226 timeval_to_EMACS_TIME (proc.ki_rusage_ch.ru_utime), 3219 timeval_to_EMACS_TIME (proc.ki_rusage_ch.ru_stime));
3227 timeval_to_EMACS_TIME (proc.ki_rusage_ch.ru_stime));
3228 attrs = Fcons (Fcons (Qctime, make_lisp_time (t)), attrs); 3220 attrs = Fcons (Fcons (Qctime, make_lisp_time (t)), attrs);
3229 3221
3230 attrs = Fcons (Fcons (Qthcount, make_fixnum_or_float (proc.ki_numthreads)), 3222 attrs = Fcons (Fcons (Qthcount, make_fixnum_or_float (proc.ki_numthreads)),
@@ -3236,8 +3228,8 @@ system_process_attributes (Lisp_Object pid)
3236 attrs = Fcons (Fcons (Qrss, make_number (proc.ki_rssize * pagesize >> 10)), 3228 attrs = Fcons (Fcons (Qrss, make_number (proc.ki_rssize * pagesize >> 10)),
3237 attrs); 3229 attrs);
3238 3230
3239 EMACS_GET_TIME (now); 3231 now = current_emacs_time ();
3240 EMACS_SUB_TIME (t, now, timeval_to_EMACS_TIME (proc.ki_start)); 3232 t = sub_emacs_time (now, timeval_to_EMACS_TIME (proc.ki_start));
3241 attrs = Fcons (Fcons (Qetime, make_lisp_time (t)), attrs); 3233 attrs = Fcons (Fcons (Qetime, make_lisp_time (t)), attrs);
3242 3234
3243 len = sizeof fscale; 3235 len = sizeof fscale;
diff --git a/src/systime.h b/src/systime.h
index a03630cf936..24e9a6f4507 100644
--- a/src/systime.h
+++ b/src/systime.h
@@ -39,65 +39,92 @@ typedef unsigned long Time;
39#endif 39#endif
40#endif 40#endif
41 41
42#ifdef WINDOWSNT
43#include <sys/time.h> /* for 'struct timeval' */ 42#include <sys/time.h> /* for 'struct timeval' */
44#endif
45 43
46/* The type to use to represent temporal intervals. It can be passed 44/* The type to use to represent temporal intervals. Its address can be passed
47 as the timeout argument to the pselect system call. */ 45 as the timeout argument to the pselect system call. */
48#define EMACS_TIME struct timespec 46typedef struct timespec EMACS_TIME;
49 47
50/* Resolution of EMACS_TIME time stamps (in units per second), and log 48/* Resolution of EMACS_TIME time stamps (in units per second), and log
51 base 10 of the resolution. The log must be a positive integer. */ 49 base 10 of the resolution. The log must be a positive integer. */
52#define EMACS_TIME_RESOLUTION 1000000000 50enum { EMACS_TIME_RESOLUTION = 1000000000 };
53#define LOG10_EMACS_TIME_RESOLUTION 9 51enum { LOG10_EMACS_TIME_RESOLUTION = 9 };
54 52
55/* EMACS_SECS (TIME) is an rvalue for the seconds component of TIME. 53/* EMACS_SECS (TIME) is the seconds component of TIME.
56 EMACS_SECS_ADDR (time) is the address of the seconds component. 54 EMACS_NSECS (TIME) is the nanoseconds component of TIME.
57 EMACS_SET_SECS (TIME, SECONDS) sets that to SECONDS. 55 emacs_secs_addr (PTIME) is the address of *PTIME's seconds component. */
58 56static inline time_t EMACS_SECS (EMACS_TIME t) { return t.tv_sec; }
59 EMACS_NSECS (TIME) is an rvalue for the nanoseconds component of TIME. 57static inline int EMACS_NSECS (EMACS_TIME t) { return t.tv_nsec; }
60 EMACS_SET_NSECS (TIME, NANOSECONDS) sets that to NANOSECONDS. 58static inline time_t *emacs_secs_addr (EMACS_TIME *t) { return &t->tv_sec; }
61 59
62 EMACS_SET_SECS_NSECS (TIME, SECS, NSECS) sets both components of TIME. */ 60/* Return an Emacs time with seconds S and nanoseconds NS. */
63#define EMACS_SECS(time) ((time).tv_sec + 0) 61static inline EMACS_TIME
64#define EMACS_NSECS(time) ((time).tv_nsec + 0) 62make_emacs_time (time_t s, int ns)
65#define EMACS_SECS_ADDR(time) (&(time).tv_sec) 63{
66#define EMACS_SET_SECS(time, seconds) ((time).tv_sec = (seconds)) 64 EMACS_TIME r = { s, ns };
67#define EMACS_SET_NSECS(time, ns) ((time).tv_nsec = (ns)) 65 return r;
68#define EMACS_SET_SECS_NSECS(time, s, ns) \ 66}
69 ((void) (EMACS_SET_SECS (time, s), EMACS_SET_NSECS (time, ns))) 67
70 68/* Return an invalid Emacs time. */
71/* Convenience macros for older code that counts microseconds. */ 69static inline EMACS_TIME
72#define EMACS_SET_USECS(time, us) ((void) EMACS_SET_NSECS (time, (us) * 1000)) 70invalid_emacs_time (void)
73#define EMACS_SET_SECS_USECS(time, secs, usecs) \ 71{
74 (EMACS_SET_SECS (time, secs), EMACS_SET_USECS (time, usecs)) 72 EMACS_TIME r = { 0, -1 };
75 73 return r;
76/* Set TIME to an invalid time stamp. */ 74}
77#define EMACS_SET_INVALID_TIME(time) EMACS_SET_SECS_NSECS(time, 0, -1) 75
78 76/* Return current system time. */
79/* Set TIME to the current system time. */ 77static inline EMACS_TIME
80#define EMACS_GET_TIME(time) gettime (&(time)) 78current_emacs_time (void)
81 79{
82/* Put into DEST the result of adding SRC1 to SRC2, or of subtracting 80 EMACS_TIME r;
83 SRC2 from SRC1. On overflow, store an extremal value: ergo, if 81 gettime (&r);
84 time_t is unsigned, return 0 if the true answer would be negative. */ 82 return r;
85#define EMACS_ADD_TIME(dest, src1, src2) ((dest) = timespec_add (src1, src2)) 83}
86#define EMACS_SUB_TIME(dest, src1, src2) ((dest) = timespec_sub (src1, src2)) 84
85/* Return the result of adding A to B, or of subtracting B from A.
86 On overflow, store an extremal value: ergo, if time_t is unsigned,
87 return 0 if the true answer would be negative. */
88static inline EMACS_TIME
89add_emacs_time (EMACS_TIME a, EMACS_TIME b)
90{
91 return timespec_add (a, b);
92}
93static inline EMACS_TIME
94sub_emacs_time (EMACS_TIME a, EMACS_TIME b)
95{
96 return timespec_sub (a, b);
97}
87 98
88/* Return the sign of the valid time stamp TIME, either -1, 0, or 1. */ 99/* Return the sign of the valid time stamp TIME, either -1, 0, or 1. */
89#define EMACS_TIME_SIGN(time) timespec_sign (time) 100static inline int
101EMACS_TIME_SIGN (EMACS_TIME t)
102{
103 return timespec_sign (t);
104}
90 105
91/* Return 1 if TIME is a valid time stamp. */ 106/* Return 1 if TIME is a valid time stamp. */
92#define EMACS_TIME_VALID_P(time) (0 <= (time).tv_nsec) 107static inline int
108EMACS_TIME_VALID_P (EMACS_TIME t)
109{
110 return 0 <= t.tv_nsec;
111}
93 112
94/* Convert the double D to the greatest EMACS_TIME not greater than D. 113/* Convert the double D to the greatest EMACS_TIME not greater than D.
95 On overflow, return an extremal value. Return the minimum 114 On overflow, return an extremal value. Return the minimum
96 EMACS_TIME if D is not a number. */ 115 EMACS_TIME if D is not a number. */
97#define EMACS_TIME_FROM_DOUBLE(d) dtotimespec (d) 116static inline EMACS_TIME
117EMACS_TIME_FROM_DOUBLE (double d)
118{
119 return dtotimespec (d);
120}
98 121
99/* Convert the Emacs time T to an approximate double value D. */ 122/* Convert the Emacs time T to an approximate double value D. */
100#define EMACS_TIME_TO_DOUBLE(t) timespectod (t) 123static inline double
124EMACS_TIME_TO_DOUBLE (EMACS_TIME t)
125{
126 return timespectod (t);
127}
101 128
102/* defined in sysdep.c */ 129/* defined in sysdep.c */
103extern int set_file_times (int, const char *, EMACS_TIME, EMACS_TIME); 130extern int set_file_times (int, const char *, EMACS_TIME, EMACS_TIME);
@@ -118,12 +145,35 @@ extern EMACS_TIME lisp_time_argument (Lisp_Object);
118#endif 145#endif
119 146
120/* Compare times T1 and T2 for equality, inequality etc. */ 147/* Compare times T1 and T2 for equality, inequality etc. */
121 148static inline int
122#define EMACS_TIME_EQ(T1, T2) (timespec_cmp (T1, T2) == 0) 149EMACS_TIME_EQ (EMACS_TIME t1, EMACS_TIME t2)
123#define EMACS_TIME_NE(T1, T2) (timespec_cmp (T1, T2) != 0) 150{
124#define EMACS_TIME_GT(T1, T2) (timespec_cmp (T1, T2) > 0) 151 return timespec_cmp (t1, t2) == 0;
125#define EMACS_TIME_GE(T1, T2) (timespec_cmp (T1, T2) >= 0) 152}
126#define EMACS_TIME_LT(T1, T2) (timespec_cmp (T1, T2) < 0) 153static inline int
127#define EMACS_TIME_LE(T1, T2) (timespec_cmp (T1, T2) <= 0) 154EMACS_TIME_NE (EMACS_TIME t1, EMACS_TIME t2)
155{
156 return timespec_cmp (t1, t2) != 0;
157}
158static inline int
159EMACS_TIME_GT (EMACS_TIME t1, EMACS_TIME t2)
160{
161 return timespec_cmp (t1, t2) > 0;
162}
163static inline int
164EMACS_TIME_GE (EMACS_TIME t1, EMACS_TIME t2)
165{
166 return timespec_cmp (t1, t2) >= 0;
167}
168static inline int
169EMACS_TIME_LT (EMACS_TIME t1, EMACS_TIME t2)
170{
171 return timespec_cmp (t1, t2) < 0;
172}
173static inline int
174EMACS_TIME_LE (EMACS_TIME t1, EMACS_TIME t2)
175{
176 return timespec_cmp (t1, t2) <= 0;
177}
128 178
129#endif /* EMACS_SYSTIME_H */ 179#endif /* EMACS_SYSTIME_H */
diff --git a/src/undo.c b/src/undo.c
index bada46563a0..c90e7b62405 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -517,9 +517,9 @@ Return what remains of the list. */)
517 && CONSP (XCDR (XCDR (XCDR (cdr)))) 517 && CONSP (XCDR (XCDR (XCDR (cdr))))
518 && INTEGERP (XCAR (XCDR (XCDR (XCDR (cdr))))) 518 && INTEGERP (XCAR (XCDR (XCDR (XCDR (cdr)))))
519 && XINT (XCAR (XCDR (XCDR (XCDR (cdr))))) < 0) 519 && XINT (XCAR (XCDR (XCDR (XCDR (cdr))))) < 0)
520 EMACS_SET_SECS_NSECS 520 mod_time =
521 (mod_time, 0, 521 (make_emacs_time
522 XINT (XCAR (XCDR (XCDR (XCDR (cdr))))) / 1000); 522 (0, XINT (XCAR (XCDR (XCDR (XCDR (cdr))))) / 1000));
523 else 523 else
524 mod_time = lisp_time_argument (cdr); 524 mod_time = lisp_time_argument (cdr);
525 525
diff --git a/src/w32.c b/src/w32.c
index 167dd467e10..e8c48a50a97 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -1969,7 +1969,7 @@ gettimeofday (struct timeval *tv, struct timezone *tz)
1969 changed. We could fix that by using GetSystemTime and 1969 changed. We could fix that by using GetSystemTime and
1970 GetTimeZoneInformation, but that doesn't seem necessary, since 1970 GetTimeZoneInformation, but that doesn't seem necessary, since
1971 Emacs always calls gettimeofday with the 2nd argument NULL (see 1971 Emacs always calls gettimeofday with the 2nd argument NULL (see
1972 EMACS_GET_TIME). */ 1972 current_emacs_time). */
1973 if (tz) 1973 if (tz)
1974 { 1974 {
1975 tz->tz_minuteswest = tb.timezone; /* minutes west of Greenwich */ 1975 tz->tz_minuteswest = tb.timezone; /* minutes west of Greenwich */
diff --git a/src/xdisp.c b/src/xdisp.c
index 4c9f3fda0a8..6af0dd6e8a3 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -29308,14 +29308,14 @@ start_hourglass (void)
29308 29308
29309 if (INTEGERP (Vhourglass_delay) 29309 if (INTEGERP (Vhourglass_delay)
29310 && XINT (Vhourglass_delay) > 0) 29310 && XINT (Vhourglass_delay) > 0)
29311 EMACS_SET_SECS_NSECS (delay, 29311 delay = make_emacs_time (min (XINT (Vhourglass_delay),
29312 min (XINT (Vhourglass_delay), TYPE_MAXIMUM (time_t)), 29312 TYPE_MAXIMUM (time_t)),
29313 0); 29313 0);
29314 else if (FLOATP (Vhourglass_delay) 29314 else if (FLOATP (Vhourglass_delay)
29315 && XFLOAT_DATA (Vhourglass_delay) > 0) 29315 && XFLOAT_DATA (Vhourglass_delay) > 0)
29316 delay = EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay)); 29316 delay = EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay));
29317 else 29317 else
29318 EMACS_SET_SECS_NSECS (delay, DEFAULT_HOURGLASS_DELAY, 0); 29318 delay = make_emacs_time (DEFAULT_HOURGLASS_DELAY, 0);
29319 29319
29320 hourglass_atimer = start_atimer (ATIMER_RELATIVE, delay, 29320 hourglass_atimer = start_atimer (ATIMER_RELATIVE, delay,
29321 show_hourglass, NULL); 29321 show_hourglass, NULL);
diff --git a/src/xgselect.c b/src/xgselect.c
index 3752056bd76..04ca00274e8 100644
--- a/src/xgselect.c
+++ b/src/xgselect.c
@@ -88,8 +88,8 @@ xg_select (int fds_lim, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
88 88
89 if (tmo_in_millisec >= 0) 89 if (tmo_in_millisec >= 0)
90 { 90 {
91 EMACS_SET_SECS_USECS (tmo, tmo_in_millisec/1000, 91 tmo = make_emacs_time (tmo_in_millisec / 1000,
92 1000 * (tmo_in_millisec % 1000)); 92 1000 * 1000 * (tmo_in_millisec % 1000));
93 if (!timeout || EMACS_TIME_LT (tmo, *timeout)) 93 if (!timeout || EMACS_TIME_LT (tmo, *timeout))
94 tmop = &tmo; 94 tmop = &tmo;
95 } 95 }
diff --git a/src/xterm.c b/src/xterm.c
index 3cf6b4c349a..b5c5ce33d6c 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -3168,26 +3168,22 @@ XTflash (struct frame *f)
3168 x_flush (f); 3168 x_flush (f);
3169 3169
3170 { 3170 {
3171 EMACS_TIME wakeup, delay; 3171 EMACS_TIME delay = make_emacs_time (0, 150 * 1000 * 1000);
3172 3172 EMACS_TIME wakeup = add_emacs_time (current_emacs_time (), delay);
3173 EMACS_GET_TIME (wakeup);
3174 EMACS_SET_SECS_NSECS (delay, 0, 150 * 1000 * 1000);
3175 EMACS_ADD_TIME (wakeup, wakeup, delay);
3176 3173
3177 /* Keep waiting until past the time wakeup or any input gets 3174 /* Keep waiting until past the time wakeup or any input gets
3178 available. */ 3175 available. */
3179 while (! detect_input_pending ()) 3176 while (! detect_input_pending ())
3180 { 3177 {
3181 EMACS_TIME current, timeout; 3178 EMACS_TIME current = current_emacs_time ();
3182 3179 EMACS_TIME timeout;
3183 EMACS_GET_TIME (current);
3184 3180
3185 /* Break if result would not be positive. */ 3181 /* Break if result would not be positive. */
3186 if (EMACS_TIME_LE (wakeup, current)) 3182 if (EMACS_TIME_LE (wakeup, current))
3187 break; 3183 break;
3188 3184
3189 /* How long `select' should wait. */ 3185 /* How long `select' should wait. */
3190 EMACS_SET_SECS_NSECS (timeout, 0, 10 * 1000 * 1000); 3186 timeout = make_emacs_time (0, 10 * 1000 * 1000);
3191 3187
3192 /* Try to wait that long--but we might wake up sooner. */ 3188 /* Try to wait that long--but we might wake up sooner. */
3193 pselect (0, NULL, NULL, NULL, &timeout, NULL); 3189 pselect (0, NULL, NULL, NULL, &timeout, NULL);
@@ -8810,9 +8806,8 @@ x_wait_for_event (struct frame *f, int eventtype)
8810 8806
8811 /* Set timeout to 0.1 second. Hopefully not noticeable. 8807 /* Set timeout to 0.1 second. Hopefully not noticeable.
8812 Maybe it should be configurable. */ 8808 Maybe it should be configurable. */
8813 EMACS_SET_SECS_USECS (tmo, 0, 100000); 8809 tmo = make_emacs_time (0, 100 * 1000 * 1000);
8814 EMACS_GET_TIME (tmo_at); 8810 tmo_at = add_emacs_time (current_emacs_time (), tmo);
8815 EMACS_ADD_TIME (tmo_at, tmo_at, tmo);
8816 8811
8817 while (pending_event_wait.eventtype) 8812 while (pending_event_wait.eventtype)
8818 { 8813 {
@@ -8825,11 +8820,11 @@ x_wait_for_event (struct frame *f, int eventtype)
8825 FD_ZERO (&fds); 8820 FD_ZERO (&fds);
8826 FD_SET (fd, &fds); 8821 FD_SET (fd, &fds);
8827 8822
8828 EMACS_GET_TIME (time_now); 8823 time_now = current_emacs_time ();
8829 if (EMACS_TIME_LT (tmo_at, time_now)) 8824 if (EMACS_TIME_LT (tmo_at, time_now))
8830 break; 8825 break;
8831 8826
8832 EMACS_SUB_TIME (tmo, tmo_at, time_now); 8827 tmo = sub_emacs_time (tmo_at, time_now);
8833 if (pselect (fd + 1, &fds, NULL, NULL, &tmo, NULL) == 0) 8828 if (pselect (fd + 1, &fds, NULL, NULL, &tmo, NULL) == 0)
8834 break; /* Timeout */ 8829 break; /* Timeout */
8835 } 8830 }
@@ -10602,9 +10597,7 @@ x_activate_timeout_atimer (void)
10602 BLOCK_INPUT; 10597 BLOCK_INPUT;
10603 if (!x_timeout_atimer_activated_flag) 10598 if (!x_timeout_atimer_activated_flag)
10604 { 10599 {
10605 EMACS_TIME interval; 10600 EMACS_TIME interval = make_emacs_time (0, 100 * 1000 * 1000);
10606
10607 EMACS_SET_SECS_USECS (interval, 0, 100000);
10608 start_atimer (ATIMER_RELATIVE, interval, x_process_timeouts, 0); 10601 start_atimer (ATIMER_RELATIVE, interval, x_process_timeouts, 0);
10609 x_timeout_atimer_activated_flag = 1; 10602 x_timeout_atimer_activated_flag = 1;
10610 } 10603 }