From 43aac990c339c0fc3304aa476ebc8ea8467f107e Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 27 Aug 2013 11:47:55 -0700 Subject: [PATCH] Simplify EMACS_TIME-related code. This portability layer is no longer needed, since Emacs has been using struct timespec as a portability layer for some time. Merge from gnulib, incorporating: 2013-08-27 timespec: new convenience constants and function * src/atimer.h, src/buffer.h, src/dispextern.h, src/xgselect.h: Include rather than "systime.h"; that's all that's needed now. * src/dispnew.c: Include rather than "systime.h"; that's all that's needed now. * src/systime.h (EMACS_TIME): Remove. All uses changed to struct timespec. (EMACS_TIME_RESOLUTION): Remove. All uses changed to TIMESPEC_RESOLUTION. (LOG10_EMACS_TIME_RESOLUTION): Remove. All uses changed to LOG10_TIMESPEC_RESOLUTION. (EMACS_SECS, emacs_secs_addr): Remove. All uses changed to tv_sec. (EMACS_NSECS): Remove. All uses changed to tv_nsec. (make_emacs_time): Remove. All used changed to make_timespec. (invalid_timespec): Rename from invalid_emacs_time. All uses changed. (current_timespec): Rename from current_emacs_time. All uses changed. (add_emacs_time): Remove. All uses changed to timespec_add. (sub_emacs_time): Remove. All uses change dot timespec_sub. (EMACS_TIME_SIGN): Remove. All uses changed to timespec_sign. (timespec_valid_p): Rename from EMACS_TIME_VALID_P. All uses changed. (EMACS_TIME_FROM_DOUBLE): Remove. All uses changed to dtotimespec. (EMACS_TIME_TO_DOUBLE): Remove. All uses changed to timespectod. (current_timespec): Rename from current_emacs_time. All uses changed. (EMACS_TIME_EQ, EMACS_TIME_LT, EMACS_TIME_LE): Remove. All uses changed to timespec_cmp. * src/xgselect.c: Include , since our .h files don't. --- ChangeLog | 6 ++ lib-src/profile.c | 14 +-- lib/timespec.h | 17 ++++ src/ChangeLog | 30 ++++++ src/alloc.c | 8 +- src/atimer.c | 33 +++---- src/atimer.h | 8 +- src/buffer.c | 2 +- src/buffer.h | 10 +- src/dispextern.h | 6 +- src/dispnew.c | 16 ++- src/editfns.c | 48 ++++----- src/fileio.c | 58 +++++------ src/gtkutil.c | 10 +- src/image.c | 22 ++--- src/keyboard.c | 125 ++++++++++++------------ src/keyboard.h | 10 +- src/lread.c | 8 +- src/msdos.c | 14 +-- src/nsmenu.m | 6 +- src/nsterm.h | 2 +- src/nsterm.m | 18 ++-- src/process.c | 64 ++++++------ src/profiler.c | 4 +- src/sysdep.c | 75 +++++++------- src/systime.h | 286 +++++++++++++++++++----------------------------------- src/w32.c | 4 +- src/w32proc.c | 2 +- src/xdisp.c | 10 +- src/xgselect.c | 13 +-- src/xgselect.h | 4 +- src/xmenu.c | 4 +- src/xterm.c | 26 ++--- 33 files changed, 465 insertions(+), 498 deletions(-) rewrite src/systime.h (65%) diff --git a/ChangeLog b/ChangeLog index cefb3d5e1b8..e8504062dc3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2013-08-27 Paul Eggert + + Simplify EMACS_TIME-related code. + Merge from gnulib, incorporating: + 2013-08-27 timespec: new convenience constants and function + 2013-08-27 Dmitry Antipov * configure.ac (DOCMISC_DVI_W32, DOCMISC_HTML_W32, DOCMISC_INFO_W32) diff --git a/lib-src/profile.c b/lib-src/profile.c index ab17b52ca28..bddfea76334 100644 --- a/lib-src/profile.c +++ b/lib-src/profile.c @@ -39,17 +39,17 @@ along with GNU Emacs. If not, see . */ #include #include -static EMACS_TIME TV1; +static struct timespec TV1; static int watch_not_started = 1; /* flag */ static char time_string[INT_STRLEN_BOUND (uintmax_t) + sizeof "." - + LOG10_EMACS_TIME_RESOLUTION]; + + LOG10_TIMESPEC_RESOLUTION]; /* Reset the stopwatch to zero. */ static void reset_watch (void) { - TV1 = current_emacs_time (); + TV1 = current_timespec (); watch_not_started = 0; } @@ -60,12 +60,12 @@ reset_watch (void) static char * get_time (void) { - EMACS_TIME TV2 = sub_emacs_time (current_emacs_time (), TV1); - uintmax_t s = EMACS_SECS (TV2); - int ns = EMACS_NSECS (TV2); + struct timespec TV2 = timespec_sub (current_timespec (), TV1); + uintmax_t s = TV2.tv_sec; + int ns = TV2.tv_nsec; if (watch_not_started) exit (EXIT_FAILURE); /* call reset_watch first ! */ - sprintf (time_string, "%"PRIuMAX".%0*d", s, LOG10_EMACS_TIME_RESOLUTION, ns); + sprintf (time_string, "%"PRIuMAX".%0*d", s, LOG10_TIMESPEC_RESOLUTION, ns); return time_string; } diff --git a/lib/timespec.h b/lib/timespec.h index d665e6ccf9a..c7450ad8de0 100644 --- a/lib/timespec.h +++ b/lib/timespec.h @@ -26,6 +26,23 @@ _GL_INLINE_HEADER_BEGIN # define _GL_TIMESPEC_INLINE _GL_INLINE #endif +/* Resolution of timespec time stamps (in units per second), and log + base 10 of the resolution. */ + +enum { TIMESPEC_RESOLUTION = 1000000000 }; +enum { LOG10_TIMESPEC_RESOLUTION = 9 }; + +/* Return a timespec with seconds S and nanoseconds NS. */ + +_GL_TIMESPEC_INLINE struct timespec +make_timespec (time_t s, long int ns) +{ + struct timespec r; + r.tv_sec = s; + r.tv_nsec = ns; + return r; +} + /* Return negative, zero, positive if A < B, A == B, A > B, respectively. For each time stamp T, this code assumes that either: diff --git a/src/ChangeLog b/src/ChangeLog index 59bf6b420c6..5d5a811b3c4 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,33 @@ +2013-08-27 Paul Eggert + + Simplify EMACS_TIME-related code. + This portability layer is no longer needed, since Emacs has been + using struct timespec as a portability layer for some time. + * atimer.h, buffer.h, dispextern.h, xgselect.h: + Include rather than "systime.h"; that's all that's needed now. + * dispnew.c: Include rather than "systime.h"; + that's all that's needed now. + * systime.h (EMACS_TIME): Remove. All uses changed to struct timespec. + (EMACS_TIME_RESOLUTION): Remove. All uses changed to + TIMESPEC_RESOLUTION. + (LOG10_EMACS_TIME_RESOLUTION): Remove. All uses changed to + LOG10_TIMESPEC_RESOLUTION. + (EMACS_SECS, emacs_secs_addr): Remove. All uses changed to tv_sec. + (EMACS_NSECS): Remove. All uses changed to tv_nsec. + (make_emacs_time): Remove. All used changed to make_timespec. + (invalid_timespec): Rename from invalid_emacs_time. All uses changed. + (current_timespec): Rename from current_emacs_time. All uses changed. + (add_emacs_time): Remove. All uses changed to timespec_add. + (sub_emacs_time): Remove. All uses change dot timespec_sub. + (EMACS_TIME_SIGN): Remove. All uses changed to timespec_sign. + (timespec_valid_p): Rename from EMACS_TIME_VALID_P. All uses changed. + (EMACS_TIME_FROM_DOUBLE): Remove. All uses changed to dtotimespec. + (EMACS_TIME_TO_DOUBLE): Remove. All uses changed to timespectod. + (current_timespec): Rename from current_emacs_time. All uses changed. + (EMACS_TIME_EQ, EMACS_TIME_LT, EMACS_TIME_LE): Remove. All uses + changed to timespec_cmp. + * xgselect.c: Include , since our .h files don't. + 2013-08-27 Dmitry Antipov * xterm.h (FONT_TYPE_FOR_UNIBYTE, FONT_TYPE_FOR_MULTIBYTE:) diff --git a/src/alloc.c b/src/alloc.c index 70a23488613..ebb8ef58991 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -5233,7 +5233,7 @@ See Info node `(elisp)Garbage Collection'. */) ptrdiff_t i; bool message_p; ptrdiff_t count = SPECPDL_INDEX (); - EMACS_TIME start; + struct timespec start; Lisp_Object retval = Qnil; size_t tot_before = 0; @@ -5258,7 +5258,7 @@ See Info node `(elisp)Garbage Collection'. */) if (profiler_memory_running) tot_before = total_bytes_of_live_objects (); - start = current_emacs_time (); + start = current_timespec (); /* In case user calls debug_print during GC, don't let that cause a recursive GC. */ @@ -5521,9 +5521,9 @@ See Info node `(elisp)Garbage Collection'. */) /* Accumulate statistics. */ if (FLOATP (Vgc_elapsed)) { - EMACS_TIME since_start = sub_emacs_time (current_emacs_time (), start); + struct timespec since_start = timespec_sub (current_timespec (), start); Vgc_elapsed = make_float (XFLOAT_DATA (Vgc_elapsed) - + EMACS_TIME_TO_DOUBLE (since_start)); + + timespectod (since_start)); } gcs_done++; diff --git a/src/atimer.c b/src/atimer.c index 219b3502acc..6aef71db873 100644 --- a/src/atimer.c +++ b/src/atimer.c @@ -94,17 +94,16 @@ static struct atimer *append_atimer_lists (struct atimer *, to cancel_atimer; don't free it yourself. */ struct atimer * -start_atimer (enum atimer_type type, EMACS_TIME timestamp, atimer_callback fn, - void *client_data) +start_atimer (enum atimer_type type, struct timespec timestamp, + atimer_callback fn, void *client_data) { struct atimer *t; /* Round TIME up to the next full second if we don't have itimers. */ #ifndef HAVE_SETITIMER - if (EMACS_NSECS (timestamp) != 0 - && EMACS_SECS (timestamp) < TYPE_MAXIMUM (time_t)) - timestamp = make_emacs_time (EMACS_SECS (timestamp) + 1, 0); + if (timestamp.tv_nsec != 0 && timestamp.tv_sec < TYPE_MAXIMUM (time_t)) + timestamp = make_timespec (timestamp.tv_sec + 1, 0); #endif /* not HAVE_SETITIMER */ /* Get an atimer structure from the free-list, or allocate @@ -133,11 +132,11 @@ start_atimer (enum atimer_type type, EMACS_TIME timestamp, atimer_callback fn, break; case ATIMER_RELATIVE: - t->expiration = add_emacs_time (current_emacs_time (), timestamp); + t->expiration = timespec_add (current_timespec (), timestamp); break; case ATIMER_CONTINUOUS: - t->expiration = add_emacs_time (current_emacs_time (), timestamp); + t->expiration = timespec_add (current_timespec (), timestamp); t->interval = timestamp; break; } @@ -284,7 +283,7 @@ set_alarm (void) #ifdef HAVE_SETITIMER struct itimerval it; #endif - EMACS_TIME now, interval; + struct timespec now, interval; #ifdef HAVE_ITIMERSPEC if (alarm_timer_ok) @@ -299,10 +298,10 @@ set_alarm (void) /* Determine interval till the next timer is ripe. Don't set the interval to 0; this disables the timer. */ - now = current_emacs_time (); - interval = (EMACS_TIME_LE (atimers->expiration, now) - ? make_emacs_time (0, 1000 * 1000) - : sub_emacs_time (atimers->expiration, now)); + now = current_timespec (); + interval = (timespec_cmp (atimers->expiration, now) <= 0 + ? make_timespec (0, 1000 * 1000) + : timespec_sub (atimers->expiration, now)); #ifdef HAVE_SETITIMER @@ -310,7 +309,7 @@ set_alarm (void) it.it_value = make_timeval (interval); setitimer (ITIMER_REAL, &it, 0); #else /* not HAVE_SETITIMER */ - alarm (max (EMACS_SECS (interval), 1)); + alarm (max (interval.tv_sec, 1)); #endif /* not HAVE_SETITIMER */ } } @@ -326,7 +325,7 @@ schedule_atimer (struct atimer *t) struct atimer *a = atimers, *prev = NULL; /* Look for the first atimer that is ripe after T. */ - while (a && EMACS_TIME_LT (a->expiration, t->expiration)) + while (a && timespec_cmp (a->expiration, t->expiration) < 0) prev = a, a = a->next; /* Insert T in front of the atimer found, if any. */ @@ -341,9 +340,9 @@ schedule_atimer (struct atimer *t) static void run_timers (void) { - EMACS_TIME now = current_emacs_time (); + struct timespec now = current_timespec (); - while (atimers && EMACS_TIME_LE (atimers->expiration, now)) + while (atimers && timespec_cmp (atimers->expiration, now) <= 0) { struct atimer *t = atimers; atimers = atimers->next; @@ -351,7 +350,7 @@ run_timers (void) if (t->type == ATIMER_CONTINUOUS) { - t->expiration = add_emacs_time (now, t->interval); + t->expiration = timespec_add (now, t->interval); schedule_atimer (t); } else diff --git a/src/atimer.h b/src/atimer.h index a1825fc0933..8c4d732aa4e 100644 --- a/src/atimer.h +++ b/src/atimer.h @@ -19,8 +19,8 @@ along with GNU Emacs. If not, see . */ #ifndef EMACS_ATIMER_H #define EMACS_ATIMER_H -#include "systime.h" /* for EMACS_TIME */ #include +#include /* Forward declaration. */ @@ -52,10 +52,10 @@ struct atimer enum atimer_type type; /* Time when this timer is ripe. */ - EMACS_TIME expiration; + struct timespec expiration; /* Interval of this timer. */ - EMACS_TIME interval; + struct timespec interval; /* Function to call when timer is ripe. Interrupt input is guaranteed to not be blocked when this function is called. */ @@ -70,7 +70,7 @@ struct atimer /* Function prototypes. */ -struct atimer *start_atimer (enum atimer_type, EMACS_TIME, +struct atimer *start_atimer (enum atimer_type, struct timespec, atimer_callback, void *); void cancel_atimer (struct atimer *); void do_pending_atimers (void); diff --git a/src/buffer.c b/src/buffer.c index 58530248abc..7bc98a8b1d3 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -933,7 +933,7 @@ reset_buffer (register struct buffer *b) bset_filename (b, Qnil); bset_file_truename (b, Qnil); bset_directory (b, current_buffer ? BVAR (current_buffer, directory) : Qnil); - b->modtime = make_emacs_time (0, UNKNOWN_MODTIME_NSECS); + b->modtime = make_timespec (0, UNKNOWN_MODTIME_NSECS); b->modtime_size = -1; XSETFASTINT (BVAR (b, save_length), 0); b->last_window_start = 1; diff --git a/src/buffer.h b/src/buffer.h index 55a9e8d2a1c..bedb7890939 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -18,8 +18,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see . */ -#include /* for off_t, time_t */ -#include "systime.h" /* for EMACS_TIME */ +#include +#include INLINE_HEADER_BEGIN #ifndef BUFFER_INLINE @@ -794,13 +794,13 @@ struct buffer char local_flags[MAX_PER_BUFFER_VARS]; /* Set to the modtime of the visited file when read or written. - EMACS_NSECS (modtime) == NONEXISTENT_MODTIME_NSECS means - visited file was nonexistent. EMACS_NSECS (modtime) == + modtime.tv_nsec == NONEXISTENT_MODTIME_NSECS means + visited file was nonexistent. modtime.tv_nsec == UNKNOWN_MODTIME_NSECS means visited file modtime unknown; in no case complain about any mismatch on next save attempt. */ #define NONEXISTENT_MODTIME_NSECS (-1) #define UNKNOWN_MODTIME_NSECS (-2) - EMACS_TIME modtime; + struct timespec modtime; /* Size of the file when modtime was set. This is used to detect the case where the file grew while we were reading it, so the modtime diff --git a/src/dispextern.h b/src/dispextern.h index cb9dddd82cb..a5cb66f7d5e 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -83,7 +83,7 @@ typedef XImagePtr XImagePtr_or_DC; #endif #ifdef HAVE_WINDOW_SYSTEM -# include "systime.h" +# include #endif #ifndef HAVE_WINDOW_SYSTEM @@ -2710,7 +2710,7 @@ reset_mouse_highlight (Mouse_HLInfo *hlinfo) hlinfo->mouse_face_mouse_x = hlinfo->mouse_face_mouse_y = 0; hlinfo->mouse_face_beg_x = hlinfo->mouse_face_end_x = 0; hlinfo->mouse_face_face_id = DEFAULT_FACE_ID; - hlinfo->mouse_face_mouse_frame = NULL; + hlinfo->mouse_face_mouse_frame = NULL; hlinfo->mouse_face_window = Qnil; hlinfo->mouse_face_overlay = Qnil; hlinfo->mouse_face_past_end = 0; @@ -2914,7 +2914,7 @@ struct image { /* The time in seconds at which the image was last displayed. Set in prepare_image_for_display. */ - EMACS_TIME timestamp; + struct timespec timestamp; /* Pixmaps of the image. */ Pixmap pixmap, mask; diff --git a/src/dispnew.c b/src/dispnew.c index 3c6b89bde68..1c80facd422 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -49,12 +49,10 @@ along with GNU Emacs. If not, see . */ #include TERM_HEADER #endif /* HAVE_WINDOW_SYSTEM */ -/* Include systime.h after xterm.h to avoid double inclusion of time.h. */ - -#include "systime.h" #include #include +#include #if defined (HAVE_TERM_H) && defined (GNU_LINUX) #include /* for tgetent */ @@ -5708,9 +5706,9 @@ additional wait period, in milliseconds; this is for backwards compatibility. if (duration > 0) { - EMACS_TIME t = EMACS_TIME_FROM_DOUBLE (duration); - wait_reading_process_output (min (EMACS_SECS (t), WAIT_READING_MAX), - EMACS_NSECS (t), 0, 0, Qnil, NULL, 0); + struct timespec t = dtotimespec (duration); + wait_reading_process_output (min (t.tv_sec, WAIT_READING_MAX), + t.tv_nsec, 0, 0, Qnil, NULL, 0); } return Qnil; @@ -5757,9 +5755,9 @@ sit_for (Lisp_Object timeout, bool reading, int display_option) return Qt; else { - EMACS_TIME t = EMACS_TIME_FROM_DOUBLE (seconds); - sec = min (EMACS_SECS (t), WAIT_READING_MAX); - nsec = EMACS_NSECS (t); + struct timespec t = dtotimespec (seconds); + sec = min (t.tv_sec, WAIT_READING_MAX); + nsec = t.tv_nsec; } } else if (EQ (timeout, Qt)) diff --git a/src/editfns.c b/src/editfns.c index bbaeaea5240..9e36655f3d3 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -64,7 +64,7 @@ along with GNU Emacs. If not, see . */ extern Lisp_Object w32_get_internal_run_time (void); #endif -static Lisp_Object format_time_string (char const *, ptrdiff_t, EMACS_TIME, +static Lisp_Object format_time_string (char const *, ptrdiff_t, struct timespec, bool, struct tm *); static int tm_diff (struct tm *, struct tm *); static void update_buffer_properties (ptrdiff_t, ptrdiff_t); @@ -1420,7 +1420,7 @@ least significant 16 bits. USEC and PSEC are the microsecond and picosecond counts. */) (void) { - return make_lisp_time (current_emacs_time ()); + return make_lisp_time (current_timespec ()); } DEFUN ("get-internal-run-time", Fget_internal_run_time, Sget_internal_run_time, @@ -1450,7 +1450,7 @@ does the same thing as `current-time'. */) usecs -= 1000000; secs++; } - return make_lisp_time (make_emacs_time (secs, usecs * 1000)); + return make_lisp_time (make_timespec (secs, usecs * 1000)); #else /* ! HAVE_GETRUSAGE */ #ifdef WINDOWSNT return w32_get_internal_run_time (); @@ -1481,10 +1481,10 @@ make_time (time_t t) UNKNOWN_MODTIME_NSECS; in that case, the Lisp list contains a correspondingly negative picosecond count. */ Lisp_Object -make_lisp_time (EMACS_TIME t) +make_lisp_time (struct timespec t) { - int ns = EMACS_NSECS (t); - return make_time_tail (EMACS_SECS (t), list2i (ns / 1000, ns % 1000 * 1000)); + int ns = t.tv_nsec; + return make_time_tail (t.tv_sec, list2i (ns / 1000, ns % 1000 * 1000)); } /* Decode a Lisp list SPECIFIED_TIME that represents a time. @@ -1529,7 +1529,7 @@ disassemble_lisp_time (Lisp_Object specified_time, Lisp_Object *phigh, list, generate the corresponding time value. If RESULT is not null, store into *RESULT the converted time; - this can fail if the converted time does not fit into EMACS_TIME. + this can fail if the converted time does not fit into struct timespec. If *DRESULT is not null, store into *DRESULT the number of seconds since the start of the POSIX Epoch. @@ -1537,7 +1537,7 @@ disassemble_lisp_time (Lisp_Object specified_time, Lisp_Object *phigh, bool decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec, Lisp_Object psec, - EMACS_TIME *result, double *dresult) + struct timespec *result, double *dresult) { EMACS_INT hi, lo, us, ps; if (! (INTEGERP (high) && INTEGERP (low) @@ -1565,7 +1565,7 @@ decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec, /* Return the greatest representable time that is not greater than the requested time. */ time_t sec = hi; - *result = make_emacs_time ((sec << 16) + lo, us * 1000 + ps / 1000); + *result = make_timespec ((sec << 16) + lo, us * 1000 + ps / 1000); } else { @@ -1583,15 +1583,15 @@ decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec, /* Decode a Lisp list SPECIFIED_TIME that represents a time. If SPECIFIED_TIME is nil, use the current time. - Round the time down to the nearest EMACS_TIME value. + Round the time down to the nearest struct timespec value. Return seconds since the Epoch. Signal an error if unsuccessful. */ -EMACS_TIME +struct timespec lisp_time_argument (Lisp_Object specified_time) { - EMACS_TIME t; + struct timespec t; if (NILP (specified_time)) - t = current_emacs_time (); + t = current_timespec (); else { Lisp_Object high, low, usec, psec; @@ -1613,12 +1613,12 @@ lisp_seconds_argument (Lisp_Object specified_time) else { Lisp_Object high, low, usec, psec; - EMACS_TIME t; + struct timespec t; if (! (disassemble_lisp_time (specified_time, &high, &low, &usec, &psec) && decode_time_components (high, low, make_number (0), make_number (0), &t, 0))) error ("Invalid time specification"); - return EMACS_SECS (t); + return t.tv_sec; } } @@ -1639,8 +1639,8 @@ or (if you need time as a string) `format-time-string'. */) double t; if (NILP (specified_time)) { - EMACS_TIME now = current_emacs_time (); - t = EMACS_SECS (now) + EMACS_NSECS (now) / 1e9; + struct timespec now = current_timespec (); + t = now.tv_sec + now.tv_nsec / 1e9; } else { @@ -1758,7 +1758,7 @@ For example, to produce full ISO 8601 format, use "%Y-%m-%dT%T%z". usage: (format-time-string FORMAT-STRING &optional TIME UNIVERSAL) */) (Lisp_Object format_string, Lisp_Object timeval, Lisp_Object universal) { - EMACS_TIME t = lisp_time_argument (timeval); + struct timespec t = lisp_time_argument (timeval); struct tm tm; CHECK_STRING (format_string); @@ -1770,20 +1770,20 @@ usage: (format-time-string FORMAT-STRING &optional TIME UNIVERSAL) */) static Lisp_Object format_time_string (char const *format, ptrdiff_t formatlen, - EMACS_TIME t, bool ut, struct tm *tmp) + struct timespec t, bool ut, struct tm *tmp) { char buffer[4000]; char *buf = buffer; ptrdiff_t size = sizeof buffer; size_t len; Lisp_Object bufstring; - int ns = EMACS_NSECS (t); + int ns = t.tv_nsec; struct tm *tm; USE_SAFE_ALLOCA; while (1) { - time_t *taddr = emacs_secs_addr (&t); + time_t *taddr = &t.tv_sec; block_input (); synchronize_system_time_locale (); @@ -2068,17 +2068,17 @@ in this case, `current-time-zone' returns a list containing nil for the data it can't find. */) (Lisp_Object specified_time) { - EMACS_TIME value; + struct timespec value; int offset; struct tm *t; struct tm localtm; Lisp_Object zone_offset, zone_name; zone_offset = Qnil; - value = make_emacs_time (lisp_seconds_argument (specified_time), 0); + value = make_timespec (lisp_seconds_argument (specified_time), 0); zone_name = format_time_string ("%Z", sizeof "%Z" - 1, value, 0, &localtm); block_input (); - t = gmtime (emacs_secs_addr (&value)); + t = gmtime (&value.tv_sec); if (t) offset = tm_diff (&localtm, t); unblock_input (); diff --git a/src/fileio.c b/src/fileio.c index 7cad8d29da2..a751a73ae50 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -2045,7 +2045,7 @@ entries (depending on how Emacs was built). */) /* CopyFile retains the timestamp by default. */ else if (NILP (keep_time)) { - EMACS_TIME now; + struct timespec now; DWORD attributes; char * filename; @@ -2054,7 +2054,7 @@ entries (depending on how Emacs was built). */) /* Ensure file is writable while its modified time is set. */ attributes = GetFileAttributes (filename); SetFileAttributes (filename, attributes & ~FILE_ATTRIBUTE_READONLY); - now = current_emacs_time (); + now = current_timespec (); if (set_file_times (-1, filename, now, now)) { /* Restore original attributes. */ @@ -2178,8 +2178,8 @@ entries (depending on how Emacs was built). */) if (!NILP (keep_time)) { - EMACS_TIME atime = get_stat_atime (&st); - EMACS_TIME mtime = get_stat_mtime (&st); + struct timespec atime = get_stat_atime (&st); + struct timespec mtime = get_stat_mtime (&st); if (set_file_times (ofd, SSDATA (encoded_newname), atime, mtime)) xsignal2 (Qfile_date_error, build_string ("Cannot set file date"), newname); @@ -3286,7 +3286,7 @@ Use the current time if TIMESTAMP is nil. TIMESTAMP is in the format of { Lisp_Object absname, encoded_absname; Lisp_Object handler; - EMACS_TIME t = lisp_time_argument (timestamp); + struct timespec t = lisp_time_argument (timestamp); absname = Fexpand_file_name (filename, BVAR (current_buffer, directory)); @@ -3363,7 +3363,7 @@ otherwise, if FILE2 does not exist, the answer is t. */) if (stat (SSDATA (absname2), &st2) < 0) return Qt; - return (EMACS_TIME_LT (get_stat_mtime (&st2), get_stat_mtime (&st1)) + return (timespec_cmp (get_stat_mtime (&st2), get_stat_mtime (&st1)) < 0 ? Qt : Qnil); } @@ -3463,13 +3463,13 @@ file_offset (Lisp_Object val) } /* Return a special time value indicating the error number ERRNUM. */ -static EMACS_TIME +static struct timespec time_error_value (int errnum) { int ns = (errnum == ENOENT || errnum == EACCES || errnum == ENOTDIR ? NONEXISTENT_MODTIME_NSECS : UNKNOWN_MODTIME_NSECS); - return make_emacs_time (0, ns); + return make_timespec (0, ns); } DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents, @@ -3501,7 +3501,7 @@ by calling `format-decode', which see. */) (Lisp_Object filename, Lisp_Object visit, Lisp_Object beg, Lisp_Object end, Lisp_Object replace) { struct stat st; - EMACS_TIME mtime; + struct timespec mtime; int fd; ptrdiff_t inserted = 0; ptrdiff_t how_much; @@ -4567,7 +4567,7 @@ by calling `format-decode', which see. */) } if (!NILP (visit) - && EMACS_NSECS (current_buffer->modtime) == NONEXISTENT_MODTIME_NSECS) + && current_buffer->modtime.tv_nsec == NONEXISTENT_MODTIME_NSECS) { /* If visiting nonexistent file, return nil. */ report_file_errno ("Opening input file", orig_filename, save_errno); @@ -4766,7 +4766,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, int save_errno = 0; const char *fn; struct stat st; - EMACS_TIME modtime; + struct timespec modtime; ptrdiff_t count = SPECPDL_INDEX (); ptrdiff_t count1 IF_LINT (= 0); Lisp_Object handler; @@ -4980,7 +4980,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, } } - modtime = invalid_emacs_time (); + modtime = invalid_timespec (); if (visiting) { if (fstat (desc, &st) == 0) @@ -5014,7 +5014,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, unlikely and a similar race between the last write and the fstat above cannot possibly be closed anyway. */ - if (EMACS_TIME_VALID_P (modtime) + if (timespec_valid_p (modtime) && ! (valid_timestamp_file_system && st.st_dev == timestamp_file_system)) { int desc1 = emacs_open (fn, O_WRONLY | O_BINARY, 0); @@ -5036,11 +5036,11 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, bool use_heuristic = ((open_flags & (O_EXCL | O_TRUNC)) != 0 && st.st_size != 0 - && EMACS_NSECS (modtime) % 100 != 0); + && modtime.tv_nsec % 100 != 0); - EMACS_TIME modtime1 = get_stat_mtime (&st1); + struct timespec modtime1 = get_stat_mtime (&st1); if (use_heuristic - && EMACS_TIME_EQ (modtime, modtime1) + && timespec_cmp (modtime, modtime1) == 0 && st.st_size == st1.st_size) { timestamp_file_system = st.st_dev; @@ -5080,7 +5080,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, /* Do this before reporting IO error to avoid a "file has changed on disk" warning on next attempt to save. */ - if (EMACS_TIME_VALID_P (modtime)) + if (timespec_valid_p (modtime)) { current_buffer->modtime = modtime; current_buffer->modtime_size = st.st_size; @@ -5355,7 +5355,7 @@ See Info node `(elisp)Modification Time' for more details. */) struct stat st; Lisp_Object handler; Lisp_Object filename; - EMACS_TIME mtime; + struct timespec mtime; if (NILP (buf)) b = current_buffer; @@ -5366,7 +5366,7 @@ See Info node `(elisp)Modification Time' for more details. */) } if (!STRINGP (BVAR (b, filename))) return Qt; - if (EMACS_NSECS (b->modtime) == UNKNOWN_MODTIME_NSECS) return Qt; + if (b->modtime.tv_nsec == UNKNOWN_MODTIME_NSECS) return Qt; /* If the file name has special constructs in it, call the corresponding file handler. */ @@ -5380,7 +5380,7 @@ See Info node `(elisp)Modification Time' for more details. */) mtime = (stat (SSDATA (filename), &st) == 0 ? get_stat_mtime (&st) : time_error_value (errno)); - if (EMACS_TIME_EQ (mtime, b->modtime) + if (timespec_cmp (mtime, b->modtime) == 0 && (b->modtime_size < 0 || st.st_size == b->modtime_size)) return Qt; @@ -5397,7 +5397,7 @@ doesn't exist, return -1. See Info node `(elisp)Modification Time' for more details. */) (void) { - int ns = EMACS_NSECS (current_buffer->modtime); + int ns = current_buffer->modtime.tv_nsec; if (ns < 0) return make_number (UNKNOWN_MODTIME_NSECS - ns); return make_lisp_time (current_buffer->modtime); @@ -5416,11 +5416,11 @@ An argument specifies the modification time value to use { if (!NILP (time_flag)) { - EMACS_TIME mtime; + struct timespec mtime; if (INTEGERP (time_flag)) { CHECK_RANGED_INTEGER (time_flag, -1, 0); - mtime = make_emacs_time (0, UNKNOWN_MODTIME_NSECS - XINT (time_flag)); + mtime = make_timespec (0, UNKNOWN_MODTIME_NSECS - XINT (time_flag)); } else mtime = lisp_time_argument (time_flag); @@ -5683,12 +5683,12 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */) || NILP (Ffind_file_name_handler (BVAR (b, auto_save_file_name), Qwrite_region)))) { - EMACS_TIME before_time = current_emacs_time (); - EMACS_TIME after_time; + struct timespec before_time = current_timespec (); + struct timespec after_time; /* If we had a failure, don't try again for 20 minutes. */ if (b->auto_save_failure_time > 0 - && EMACS_SECS (before_time) - b->auto_save_failure_time < 1200) + && before_time.tv_sec - b->auto_save_failure_time < 1200) continue; set_buffer_internal (b); @@ -5721,12 +5721,12 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */) XSETFASTINT (BVAR (current_buffer, save_length), Z - BEG); set_buffer_internal (old); - after_time = current_emacs_time (); + after_time = current_timespec (); /* If auto-save took more than 60 seconds, assume it was an NFS failure that got a timeout. */ - if (EMACS_SECS (after_time) - EMACS_SECS (before_time) > 60) - b->auto_save_failure_time = EMACS_SECS (after_time); + if (after_time.tv_sec - before_time.tv_sec > 60) + b->auto_save_failure_time = after_time.tv_sec; } } diff --git a/src/gtkutil.c b/src/gtkutil.c index 0de748654eb..f03ca592834 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -1685,15 +1685,15 @@ static gboolean xg_maybe_add_timer (gpointer data) { struct xg_dialog_data *dd = data; - EMACS_TIME next_time = timer_check (); + struct timespec next_time = timer_check (); dd->timerid = 0; - if (EMACS_TIME_VALID_P (next_time)) + if (timespec_valid_p (next_time)) { - time_t s = EMACS_SECS (next_time); - int per_ms = EMACS_TIME_RESOLUTION / 1000; - int ms = (EMACS_NSECS (next_time) + per_ms - 1) / per_ms; + time_t s = next_time.tv_sec; + int per_ms = TIMESPEC_RESOLUTION / 1000; + int ms = (next_time.tv_nsec + per_ms - 1) / per_ms; if (s <= ((guint) -1 - ms) / 1000) dd->timerid = g_timeout_add (s * 1000 + ms, xg_maybe_add_timer, dd); } diff --git a/src/image.c b/src/image.c index 8d9c33de12c..bcc0fcd78a3 100644 --- a/src/image.c +++ b/src/image.c @@ -1041,7 +1041,7 @@ void prepare_image_for_display (struct frame *f, struct image *img) { /* We're about to display IMG, so set its timestamp to `now'. */ - img->timestamp = current_emacs_time (); + img->timestamp = current_timespec (); /* If IMG doesn't have a pixmap yet, load it now, using the image type dependent loader function. */ @@ -1480,7 +1480,7 @@ clear_image_cache (struct frame *f, Lisp_Object filter) else if (INTEGERP (Vimage_cache_eviction_delay)) { /* Free cache based on timestamp. */ - EMACS_TIME old, t; + struct timespec old, t; double delay; ptrdiff_t nimages = 0; @@ -1495,13 +1495,13 @@ clear_image_cache (struct frame *f, Lisp_Object filter) delay = 1600 * delay / nimages / nimages; delay = max (delay, 1); - t = current_emacs_time (); - old = sub_emacs_time (t, EMACS_TIME_FROM_DOUBLE (delay)); + t = current_timespec (); + old = timespec_sub (t, dtotimespec (delay)); for (i = 0; i < c->used; ++i) { struct image *img = c->images[i]; - if (img && EMACS_TIME_LT (img->timestamp, old)) + if (img && timespec_cmp (img->timestamp, old) < 0) { free_image (f, img); ++nfreed; @@ -1764,7 +1764,7 @@ lookup_image (struct frame *f, Lisp_Object spec) } /* We're using IMG, so set its timestamp to `now'. */ - img->timestamp = current_emacs_time (); + img->timestamp = current_timespec (); /* Value is the image id. */ return img->id; @@ -7884,7 +7884,7 @@ struct animation_cache { MagickWand *wand; int index; - EMACS_TIME update_time; + struct timespec update_time; struct animation_cache *next; char signature[FLEXIBLE_ARRAY_MEMBER]; }; @@ -7909,13 +7909,13 @@ static void imagemagick_prune_animation_cache (void) { struct animation_cache **pcache = &animation_cache; - EMACS_TIME old = sub_emacs_time (current_emacs_time (), - make_emacs_time (60, 0)); + struct timespec old = timespec_sub (current_timespec (), + make_timespec (60, 0)); while (*pcache) { struct animation_cache *cache = *pcache; - if (EMACS_TIME_LE (old, cache->update_time)) + if (timespec_cmp (old, cache->update_time) <= 0) pcache = &cache->next; else { @@ -7950,7 +7950,7 @@ imagemagick_get_animation_cache (MagickWand *wand) } DestroyString (signature); - cache->update_time = current_emacs_time (); + cache->update_time = current_timespec (); return cache; } diff --git a/src/keyboard.c b/src/keyboard.c index 8a99d5a0766..b8e05cf7925 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -360,7 +360,7 @@ Lisp_Object Qmenu_bar; static void recursive_edit_unwind (Lisp_Object buffer); static Lisp_Object command_loop (void); static Lisp_Object Qcommand_execute; -EMACS_TIME timer_check (void); +struct timespec timer_check (void); static void echo_now (void); static ptrdiff_t echo_length (void); @@ -370,9 +370,9 @@ static Lisp_Object Qpolling_period; /* Incremented whenever a timer is run. */ unsigned timers_run; -/* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt +/* Address (if not 0) of struct timespec to zero out if a SIGIO interrupt happens. */ -EMACS_TIME *input_available_clear_time; +struct timespec *input_available_clear_time; /* True means use SIGIO interrupts; false means use CBREAK mode. Default is true if INTERRUPT_INPUT is defined. */ @@ -389,12 +389,12 @@ bool interrupts_deferred; /* The time when Emacs started being idle. */ -static EMACS_TIME timer_idleness_start_time; +static struct timespec timer_idleness_start_time; /* After Emacs stops being idle, this saves the last value of timer_idleness_start_time from when it was idle. */ -static EMACS_TIME timer_last_idleness_start_time; +static struct timespec timer_last_idleness_start_time; /* Global variable declarations. */ @@ -1986,10 +1986,10 @@ start_polling (void) /* If poll timer doesn't exist, are we need one with a different interval, start a new one. */ if (poll_timer == NULL - || EMACS_SECS (poll_timer->interval) != polling_period) + || poll_timer->interval.tv_sec != polling_period) { time_t period = max (1, min (polling_period, TYPE_MAXIMUM (time_t))); - EMACS_TIME interval = make_emacs_time (period, 0); + struct timespec interval = make_timespec (period, 0); if (poll_timer) cancel_atimer (poll_timer); @@ -2182,7 +2182,7 @@ show_help_echo (Lisp_Object help, Lisp_Object window, Lisp_Object object, /* Input of single characters from keyboard */ static Lisp_Object kbd_buffer_get_event (KBOARD **kbp, bool *used_mouse_menu, - EMACS_TIME *end_time); + struct timespec *end_time); static void record_char (Lisp_Object c); static Lisp_Object help_form_saved_window_configs; @@ -2204,7 +2204,7 @@ do { if (polling_stopped_here) start_polling (); \ polling_stopped_here = 0; } while (0) static Lisp_Object -read_event_from_main_queue (EMACS_TIME *end_time, +read_event_from_main_queue (struct timespec *end_time, sys_jmp_buf local_getcjmp, bool *used_mouse_menu) { @@ -2217,7 +2217,7 @@ read_event_from_main_queue (EMACS_TIME *end_time, /* Read from the main queue, and if that gives us something we can't use yet, we put it on the appropriate side queue and try again. */ - if (end_time && EMACS_TIME_LE (*end_time, current_emacs_time ())) + if (end_time && timespec_cmp (*end_time, current_timespec ()) <= 0) return c; /* Actually read a character, waiting if necessary. */ @@ -2278,7 +2278,7 @@ read_event_from_main_queue (EMACS_TIME *end_time, /* Like `read_event_from_main_queue' but applies keyboard-coding-system to tty input. */ static Lisp_Object -read_decoded_event_from_main_queue (EMACS_TIME *end_time, +read_decoded_event_from_main_queue (struct timespec *end_time, sys_jmp_buf local_getcjmp, Lisp_Object prev_event, bool *used_mouse_menu) @@ -2376,7 +2376,7 @@ read_decoded_event_from_main_queue (EMACS_TIME *end_time, Value is -2 when we find input on another keyboard. A second call to read_char will read it. - If END_TIME is non-null, it is a pointer to an EMACS_TIME + If END_TIME is non-null, it is a pointer to a struct timespec specifying the maximum time to wait until. If no input arrives by that time, stop waiting and return nil. @@ -2385,7 +2385,7 @@ read_decoded_event_from_main_queue (EMACS_TIME *end_time, Lisp_Object read_char (int commandflag, Lisp_Object map, Lisp_Object prev_event, - bool *used_mouse_menu, EMACS_TIME *end_time) + bool *used_mouse_menu, struct timespec *end_time) { Lisp_Object c; ptrdiff_t jmpcount; @@ -2877,7 +2877,7 @@ read_char (int commandflag, Lisp_Object map, { c = read_decoded_event_from_main_queue (end_time, local_getcjmp, prev_event, used_mouse_menu); - if (end_time && EMACS_TIME_LE (*end_time, current_emacs_time ())) + if (end_time && timespec_cmp (*end_time, current_timespec ()) <= 0) goto exit; if (EQ (c, make_number (-2))) { @@ -3798,7 +3798,7 @@ clear_event (struct input_event *event) static Lisp_Object kbd_buffer_get_event (KBOARD **kbp, bool *used_mouse_menu, - EMACS_TIME *end_time) + struct timespec *end_time) { Lisp_Object obj; @@ -3856,15 +3856,15 @@ kbd_buffer_get_event (KBOARD **kbp, break; if (end_time) { - EMACS_TIME now = current_emacs_time (); - if (EMACS_TIME_LE (*end_time, now)) + struct timespec now = current_timespec (); + if (timespec_cmp (*end_time, now) <= 0) return Qnil; /* Finished waiting. */ else { - EMACS_TIME duration = sub_emacs_time (*end_time, now); - wait_reading_process_output (min (EMACS_SECS (duration), + struct timespec duration = timespec_sub (*end_time, now); + wait_reading_process_output (min (duration.tv_sec, WAIT_READING_MAX), - EMACS_NSECS (duration), + duration.tv_nsec, -1, 1, Qnil, NULL, 0); } } @@ -4295,10 +4295,10 @@ static void timer_start_idle (void) { /* If we are already in the idle state, do nothing. */ - if (EMACS_TIME_VALID_P (timer_idleness_start_time)) + if (timespec_valid_p (timer_idleness_start_time)) return; - timer_idleness_start_time = current_emacs_time (); + timer_idleness_start_time = current_timespec (); timer_last_idleness_start_time = timer_idleness_start_time; /* Mark all idle-time timers as once again candidates for running. */ @@ -4310,7 +4310,7 @@ timer_start_idle (void) static void timer_stop_idle (void) { - timer_idleness_start_time = invalid_emacs_time (); + timer_idleness_start_time = invalid_timespec (); } /* Resume idle timer from last idle start time. */ @@ -4318,7 +4318,7 @@ timer_stop_idle (void) static void timer_resume_idle (void) { - if (EMACS_TIME_VALID_P (timer_idleness_start_time)) + if (timespec_valid_p (timer_idleness_start_time)) return; timer_idleness_start_time = timer_last_idleness_start_time; @@ -4334,7 +4334,7 @@ Lisp_Object pending_funcalls; /* Return true if TIMER is a valid timer, placing its value into *RESULT. */ static bool -decode_timer (Lisp_Object timer, EMACS_TIME *result) +decode_timer (Lisp_Object timer, struct timespec *result) { Lisp_Object *vector; @@ -4361,16 +4361,16 @@ decode_timer (Lisp_Object timer, EMACS_TIME *result) In that case we return 0 to indicate that a new timer_check_2 call should be done. */ -static EMACS_TIME +static struct timespec timer_check_2 (Lisp_Object timers, Lisp_Object idle_timers) { - EMACS_TIME nexttime; - EMACS_TIME now; - EMACS_TIME idleness_now; + struct timespec nexttime; + struct timespec now; + struct timespec idleness_now; Lisp_Object chosen_timer; struct gcpro gcpro1; - nexttime = invalid_emacs_time (); + nexttime = invalid_timespec (); chosen_timer = Qnil; GCPRO1 (chosen_timer); @@ -4385,19 +4385,19 @@ timer_check_2 (Lisp_Object timers, Lisp_Object idle_timers) if (CONSP (timers) || CONSP (idle_timers)) { - now = current_emacs_time (); - idleness_now = (EMACS_TIME_VALID_P (timer_idleness_start_time) - ? sub_emacs_time (now, timer_idleness_start_time) - : make_emacs_time (0, 0)); + now = current_timespec (); + idleness_now = (timespec_valid_p (timer_idleness_start_time) + ? timespec_sub (now, timer_idleness_start_time) + : make_timespec (0, 0)); } while (CONSP (timers) || CONSP (idle_timers)) { Lisp_Object timer = Qnil, idle_timer = Qnil; - EMACS_TIME timer_time, idle_timer_time; - EMACS_TIME difference; - EMACS_TIME timer_difference = invalid_emacs_time (); - EMACS_TIME idle_timer_difference = invalid_emacs_time (); + struct timespec timer_time, idle_timer_time; + struct timespec difference; + struct timespec timer_difference = invalid_timespec (); + struct timespec idle_timer_difference = invalid_timespec (); bool ripe, timer_ripe = 0, idle_timer_ripe = 0; /* Set TIMER and TIMER_DIFFERENCE @@ -4414,10 +4414,10 @@ timer_check_2 (Lisp_Object timers, Lisp_Object idle_timers) continue; } - timer_ripe = EMACS_TIME_LE (timer_time, now); + timer_ripe = timespec_cmp (timer_time, now) <= 0; timer_difference = (timer_ripe - ? sub_emacs_time (now, timer_time) - : sub_emacs_time (timer_time, now)); + ? timespec_sub (now, timer_time) + : timespec_sub (timer_time, now)); } /* Likewise for IDLE_TIMER and IDLE_TIMER_DIFFERENCE @@ -4431,26 +4431,27 @@ timer_check_2 (Lisp_Object timers, Lisp_Object idle_timers) continue; } - idle_timer_ripe = EMACS_TIME_LE (idle_timer_time, idleness_now); + idle_timer_ripe = timespec_cmp (idle_timer_time, idleness_now) <= 0; idle_timer_difference = (idle_timer_ripe - ? sub_emacs_time (idleness_now, idle_timer_time) - : sub_emacs_time (idle_timer_time, idleness_now)); + ? timespec_sub (idleness_now, idle_timer_time) + : timespec_sub (idle_timer_time, idleness_now)); } /* Decide which timer is the next timer, and set CHOSEN_TIMER, DIFFERENCE, and RIPE accordingly. Also step down the list where we found that timer. */ - if (EMACS_TIME_VALID_P (timer_difference) - && (! EMACS_TIME_VALID_P (idle_timer_difference) + if (timespec_valid_p (timer_difference) + && (! timespec_valid_p (idle_timer_difference) || idle_timer_ripe < timer_ripe || (idle_timer_ripe == timer_ripe - && (timer_ripe - ? EMACS_TIME_LT (idle_timer_difference, + && ((timer_ripe + ? timespec_cmp (idle_timer_difference, timer_difference) - : EMACS_TIME_LT (timer_difference, - idle_timer_difference))))) + : timespec_cmp (timer_difference, + idle_timer_difference)) + < 0)))) { chosen_timer = timer; timers = XCDR (timers); @@ -4490,7 +4491,7 @@ timer_check_2 (Lisp_Object timers, Lisp_Object idle_timers) return 0 to indicate that. */ } - nexttime = make_emacs_time (0, 0); + nexttime = make_timespec (0, 0); break; } else @@ -4518,10 +4519,10 @@ timer_check_2 (Lisp_Object timers, Lisp_Object idle_timers) As long as any timer is ripe, we run it. */ -EMACS_TIME +struct timespec timer_check (void) { - EMACS_TIME nexttime; + struct timespec nexttime; Lisp_Object timers, idle_timers; struct gcpro gcpro1, gcpro2; @@ -4535,7 +4536,7 @@ timer_check (void) /* Always consider the ordinary timers. */ timers = Fcopy_sequence (Vtimer_list); /* Consider the idle timers only if Emacs is idle. */ - if (EMACS_TIME_VALID_P (timer_idleness_start_time)) + if (timespec_valid_p (timer_idleness_start_time)) idle_timers = Fcopy_sequence (Vtimer_idle_list); else idle_timers = Qnil; @@ -4548,7 +4549,7 @@ timer_check (void) { nexttime = timer_check_2 (timers, idle_timers); } - while (EMACS_SECS (nexttime) == 0 && EMACS_NSECS (nexttime) == 0); + while (nexttime.tv_sec == 0 && nexttime.tv_nsec == 0); UNGCPRO; return nexttime; @@ -4564,9 +4565,9 @@ The value when Emacs is not idle is nil. PSEC is a multiple of the system clock resolution. */) (void) { - if (EMACS_TIME_VALID_P (timer_idleness_start_time)) - return make_lisp_time (sub_emacs_time (current_emacs_time (), - timer_idleness_start_time)); + if (timespec_valid_p (timer_idleness_start_time)) + return make_lisp_time (timespec_sub (current_timespec (), + timer_idleness_start_time)); return Qnil; } @@ -7126,7 +7127,7 @@ handle_input_available_signal (int sig) pending_signals = 1; if (input_available_clear_time) - *input_available_clear_time = make_emacs_time (0, 0); + *input_available_clear_time = make_timespec (0, 0); } static void @@ -7213,7 +7214,7 @@ handle_user_signal (int sig) /* Tell wait_reading_process_output that it needs to wake up and look around. */ if (input_available_clear_time) - *input_available_clear_time = make_emacs_time (0, 0); + *input_available_clear_time = make_timespec (0, 0); } break; } @@ -10235,7 +10236,7 @@ stuff_buffered_input (Lisp_Object stuffstring) } void -set_waiting_for_input (EMACS_TIME *time_to_clear) +set_waiting_for_input (struct timespec *time_to_clear) { input_available_clear_time = time_to_clear; @@ -10846,7 +10847,7 @@ init_keyboard (void) immediate_quit = 0; quit_char = Ctl ('g'); Vunread_command_events = Qnil; - timer_idleness_start_time = invalid_emacs_time (); + timer_idleness_start_time = invalid_timespec (); total_keys = 0; recent_keys_index = 0; kbd_fetch_ptr = kbd_buffer; diff --git a/src/keyboard.h b/src/keyboard.h index daba94898d8..0953f1b7cfd 100644 --- a/src/keyboard.h +++ b/src/keyboard.h @@ -17,7 +17,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see . */ -#include "systime.h" /* for EMACS_TIME, Time */ +#include "systime.h" /* for struct timespec, Time */ #include "coding.h" /* for ENCODE_UTF_8 and ENCODE_SYSTEM */ INLINE_HEADER_BEGIN @@ -466,9 +466,9 @@ extern Lisp_Object Qmode_line, Qvertical_line, Qheader_line; /* True while doing kbd input. */ extern bool waiting_for_input; -/* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt +/* Address (if not 0) of struct timespec to zero out if a SIGIO interrupt happens. */ -extern EMACS_TIME *input_available_clear_time; +extern struct timespec *input_available_clear_time; #if defined HAVE_WINDOW_SYSTEM && !defined USE_GTK && !defined HAVE_NS extern bool ignore_mouse_drag_p; @@ -483,7 +483,7 @@ struct input_event; extern Lisp_Object parse_modifiers (Lisp_Object); extern Lisp_Object reorder_modifiers (Lisp_Object); extern Lisp_Object read_char (int, Lisp_Object, Lisp_Object, - bool *, EMACS_TIME *); + bool *, struct timespec *); extern int parse_solitary_modifier (Lisp_Object symbol); @@ -549,7 +549,7 @@ extern bool kbd_buffer_events_waiting (void); extern void add_user_signal (int, const char *); extern int tty_read_avail_input (struct terminal *, struct input_event *); -extern EMACS_TIME timer_check (void); +extern struct timespec timer_check (void); extern void mark_kboards (void); #ifdef HAVE_NTGUI diff --git a/src/lread.c b/src/lread.c index 1f90970e93c..9518631ba6d 100644 --- a/src/lread.c +++ b/src/lread.c @@ -609,7 +609,7 @@ read_filtered_event (bool no_switch_frame, bool ascii_required, bool error_nonascii, bool input_method, Lisp_Object seconds) { Lisp_Object val, delayed_switch_frame; - EMACS_TIME end_time; + struct timespec end_time; #ifdef HAVE_WINDOW_SYSTEM if (display_hourglass_p) @@ -622,8 +622,8 @@ read_filtered_event (bool no_switch_frame, bool ascii_required, if (NUMBERP (seconds)) { double duration = extract_float (seconds); - EMACS_TIME wait_time = EMACS_TIME_FROM_DOUBLE (duration); - end_time = add_emacs_time (current_emacs_time (), wait_time); + struct timespec wait_time = dtotimespec (duration); + end_time = timespec_add (current_timespec (), wait_time); } /* Read until we get an acceptable event. */ @@ -1262,7 +1262,7 @@ Return t if the file exists and loads successfully. */) } if (result == 0 - && EMACS_TIME_LT (get_stat_mtime (&s1), get_stat_mtime (&s2))) + && timespec_cmp (get_stat_mtime (&s1), get_stat_mtime (&s2)) < 0) { /* Make the progress messages mention that source is newer. */ newer = 1; diff --git a/src/msdos.c b/src/msdos.c index 6018f72bfae..3c78efbc47b 100644 --- a/src/msdos.c +++ b/src/msdos.c @@ -4055,7 +4055,7 @@ dos_yield_time_slice (void) because wait_reading_process_output takes care of that. */ int sys_select (int nfds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, - EMACS_TIME *timeout, void *ignored) + struct timespec *timeout, void *ignored) { int check_input; struct timespec t; @@ -4085,20 +4085,20 @@ sys_select (int nfds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, } else { - EMACS_TIME clnow, cllast, cldiff; + struct timespec clnow, cllast, cldiff; gettime (&t); - cllast = make_emacs_time (t.tv_sec, t.tv_nsec); + cllast = make_timespec (t.tv_sec, t.tv_nsec); while (!check_input || !detect_input_pending ()) { gettime (&t); - clnow = make_emacs_time (t.tv_sec, t.tv_nsec); - cldiff = sub_emacs_time (clnow, cllast); - *timeout = sub_emacs_time (*timeout, cldiff); + clnow = make_timespec (t.tv_sec, t.tv_nsec); + cldiff = timespec_sub (clnow, cllast); + *timeout = timespec_sub (*timeout, cldiff); /* Stop when timeout value crosses zero. */ - if (EMACS_TIME_SIGN (*timeout) <= 0) + if (timespec_sign (*timeout) <= 0) return 0; cllast = clnow; dos_yield_time_slice (); diff --git a/src/nsmenu.m b/src/nsmenu.m index 7fe84343f1c..f9cd511efe9 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m @@ -1867,11 +1867,11 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header) while (popup_activated_flag) { NSTimer *tmo = nil; - EMACS_TIME next_time = timer_check (); + struct timespec next_time = timer_check (); - if (EMACS_TIME_VALID_P (next_time)) + if (timespec_valid_p (next_time)) { - double time = EMACS_TIME_TO_DOUBLE (next_time); + double time = timespectod (next_time); tmo = [NSTimer timerWithTimeInterval: time target: self selector: @selector (timeout_handler:) diff --git a/src/nsterm.h b/src/nsterm.h index 4815cc4bb48..4e07d796250 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -872,7 +872,7 @@ extern int x_display_pixel_width (struct ns_display_info *); /* This in nsterm.m */ extern void x_destroy_window (struct frame *f); extern int ns_select (int nfds, fd_set *readfds, fd_set *writefds, - fd_set *exceptfds, EMACS_TIME const *timeout, + fd_set *exceptfds, struct timespec const *timeout, sigset_t const *sigmask); extern unsigned long ns_get_rgb_color (struct frame *f, float r, float g, float b, float a); diff --git a/src/nsterm.m b/src/nsterm.m index f7f7b897830..ec365df0c22 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -214,7 +214,7 @@ static NSTimer *scroll_repeat_entry = nil; static fd_set select_readfds, select_writefds; enum { SELECT_HAVE_READ = 1, SELECT_HAVE_WRITE = 2, SELECT_HAVE_TMO = 4 }; static int select_nfds = 0, select_valid = 0; -static EMACS_TIME select_timeout = { 0, 0 }; +static struct timespec select_timeout = { 0, 0 }; static int selfds[2] = { -1, -1 }; static pthread_mutex_t select_mutex; static int apploopnr = 0; @@ -485,16 +485,16 @@ ns_timeout (int usecs) Blocking timer utility used by ns_ring_bell -------------------------------------------------------------------------- */ { - EMACS_TIME wakeup = add_emacs_time (current_emacs_time (), - make_emacs_time (0, usecs * 1000)); + struct timespec wakeup = timespec_add (current_timespec (), + make_timespec (0, usecs * 1000)); /* Keep waiting until past the time wakeup. */ while (1) { - EMACS_TIME timeout, now = current_emacs_time (); - if (EMACS_TIME_LE (wakeup, now)) + struct timespec timeout, now = current_timespec (); + if (timespec_cmp (wakeup, now) <= 0) break; - timeout = sub_emacs_time (wakeup, now); + timeout = timespec_sub (wakeup, now); /* Try to wait that long--but we might wake up sooner. */ pselect (0, NULL, NULL, NULL, &timeout, NULL); @@ -3529,7 +3529,7 @@ ns_read_socket (struct terminal *terminal, struct input_event *hold_quit) int ns_select (int nfds, fd_set *readfds, fd_set *writefds, - fd_set *exceptfds, EMACS_TIME const *timeout, + fd_set *exceptfds, struct timespec const *timeout, sigset_t const *sigmask) /* -------------------------------------------------------------------------- Replacement for select, checking for events @@ -3600,7 +3600,7 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds, else if (nr == 0 && timeout) { /* No file descriptor, just a timeout, no need to wake fd_handler */ - double time = EMACS_TIME_TO_DOUBLE (*timeout); + double time = timespectod (*timeout); timed_entry = [[NSTimer scheduledTimerWithTimeInterval: time target: NSApp selector: @@ -4687,7 +4687,7 @@ not_in_argv (NSString *arg) char c; SELECT_TYPE readfds, writefds, *wfds; - EMACS_TIME timeout, *tmo; + struct timespec timeout, *tmo; NSAutoreleasePool *pool = nil; /* NSTRACE (fd_handler); */ diff --git a/src/process.c b/src/process.c index c5e691bf602..3b62f45bf0a 100644 --- a/src/process.c +++ b/src/process.c @@ -133,7 +133,7 @@ along with GNU Emacs. If not, see . */ #ifdef WINDOWSNT extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *, - EMACS_TIME *, void *); + struct timespec *, void *); #endif #ifndef SOCK_CLOEXEC @@ -261,7 +261,7 @@ static EMACS_INT update_tick; #endif #ifdef ADAPTIVE_READ_BUFFERING -#define READ_OUTPUT_DELAY_INCREMENT (EMACS_TIME_RESOLUTION / 100) +#define READ_OUTPUT_DELAY_INCREMENT (TIMESPEC_RESOLUTION / 100) #define READ_OUTPUT_DELAY_MAX (READ_OUTPUT_DELAY_INCREMENT * 5) #define READ_OUTPUT_DELAY_MAX_MAX (READ_OUTPUT_DELAY_INCREMENT * 7) @@ -3932,9 +3932,9 @@ Return non-nil if we received any output before the timeout expired. */) { if (XFLOAT_DATA (seconds) > 0) { - EMACS_TIME t = EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (seconds)); - secs = min (EMACS_SECS (t), WAIT_READING_MAX); - nsecs = EMACS_NSECS (t); + struct timespec t = dtotimespec (XFLOAT_DATA (seconds)); + secs = min (t.tv_sec, WAIT_READING_MAX); + nsecs = t.tv_nsec; } } else @@ -4239,7 +4239,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, bool no_avail; int xerrno; Lisp_Object proc; - EMACS_TIME timeout, end_time; + struct timespec timeout, end_time; int wait_channel = -1; bool got_some_input = 0; ptrdiff_t count = SPECPDL_INDEX (); @@ -4272,8 +4272,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, compute the absolute time to return at. */ if (time_limit || nsecs > 0) { - timeout = make_emacs_time (time_limit, nsecs); - end_time = add_emacs_time (current_emacs_time (), timeout); + timeout = make_timespec (time_limit, nsecs); + end_time = timespec_add (current_timespec (), timeout); } while (1) @@ -4300,18 +4300,18 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, gobble output available now but don't wait at all. */ - timeout = make_emacs_time (0, 0); + timeout = make_timespec (0, 0); } else if (time_limit || nsecs > 0) { - EMACS_TIME now = current_emacs_time (); - if (EMACS_TIME_LE (end_time, now)) + struct timespec now = current_timespec (); + if (timespec_cmp (end_time, now) <= 0) break; - timeout = sub_emacs_time (end_time, now); + timeout = timespec_sub (end_time, now); } else { - timeout = make_emacs_time (100000, 0); + timeout = make_timespec (100000, 0); } /* Normally we run timers here. @@ -4321,7 +4321,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, if (NILP (wait_for_cell) && just_wait_proc >= 0) { - EMACS_TIME timer_delay; + struct timespec timer_delay; do { @@ -4356,9 +4356,9 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, /* A negative timeout means do not wait at all. */ if (nsecs >= 0) { - if (EMACS_TIME_VALID_P (timer_delay)) + if (timespec_valid_p (timer_delay)) { - if (EMACS_TIME_LT (timer_delay, timeout)) + if (timespec_cmp (timer_delay, timeout) < 0) { timeout = timer_delay; timeout_reduced_for_timers = 1; @@ -4396,7 +4396,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, Atemp = input_wait_mask; Ctemp = write_mask; - timeout = make_emacs_time (0, 0); + timeout = make_timespec (0, 0); if ((pselect (max (max_process_desc, max_input_desc) + 1, &Atemp, #ifdef NON_BLOCKING_CONNECT @@ -4518,8 +4518,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, Vprocess_adaptive_read_buffering is nil. */ if (process_output_skip && check_delay > 0) { - int nsecs = EMACS_NSECS (timeout); - if (EMACS_SECS (timeout) > 0 || nsecs > READ_OUTPUT_DELAY_MAX) + int nsecs = timeout.tv_nsec; + if (timeout.tv_sec > 0 || nsecs > READ_OUTPUT_DELAY_MAX) nsecs = READ_OUTPUT_DELAY_MAX; for (channel = 0; check_delay > 0 && channel <= max_process_desc; channel++) { @@ -4539,7 +4539,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, nsecs = XPROCESS (proc)->read_output_delay; } } - timeout = make_emacs_time (0, nsecs); + timeout = make_timespec (0, nsecs); process_output_skip = 0; } #endif @@ -6543,7 +6543,7 @@ keyboard_bit_set (fd_set *mask) /* Defined on msdos.c. */ extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *, - EMACS_TIME *, void *); + struct timespec *, void *); /* Implementation of wait_reading_process_output, assuming that there are no subprocesses. Used only by the MS-DOS build. @@ -6582,7 +6582,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, struct Lisp_Process *wait_proc, int just_wait_proc) { register int nfds; - EMACS_TIME end_time, timeout; + struct timespec end_time, timeout; if (time_limit < 0) { @@ -6595,8 +6595,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, /* What does time_limit really mean? */ if (time_limit || nsecs > 0) { - timeout = make_emacs_time (time_limit, nsecs); - end_time = add_emacs_time (current_emacs_time (), timeout); + timeout = make_timespec (time_limit, nsecs); + end_time = timespec_add (current_timespec (), timeout); } /* Turn off periodic alarms (in case they are in use) @@ -6629,18 +6629,18 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, gobble output available now but don't wait at all. */ - timeout = make_emacs_time (0, 0); + timeout = make_timespec (0, 0); } else if (time_limit || nsecs > 0) { - EMACS_TIME now = current_emacs_time (); - if (EMACS_TIME_LE (end_time, now)) + struct timespec now = current_timespec (); + if (timespec_cmp (end_time, now) <= 0) break; - timeout = sub_emacs_time (end_time, now); + timeout = timespec_sub (end_time, now); } else { - timeout = make_emacs_time (100000, 0); + timeout = make_timespec (100000, 0); } /* If our caller will not immediately handle keyboard events, @@ -6649,7 +6649,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, call timer_delay on their own.) */ if (NILP (wait_for_cell)) { - EMACS_TIME timer_delay; + struct timespec timer_delay; do { @@ -6669,9 +6669,9 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, && requeued_events_pending_p ()) break; - if (EMACS_TIME_VALID_P (timer_delay) && nsecs >= 0) + if (timespec_valid_p (timer_delay) && nsecs >= 0) { - if (EMACS_TIME_LT (timer_delay, timeout)) + if (timespec_cmp (timer_delay, timeout) < 0) { timeout = timer_delay; timeout_reduced_for_timers = 1; diff --git a/src/profiler.c b/src/profiler.c index c86fb47d21d..64eb5cafc25 100644 --- a/src/profiler.c +++ b/src/profiler.c @@ -267,8 +267,8 @@ setup_cpu_timer (Lisp_Object sampling_interval) return NOT_RUNNING; current_sampling_interval = XINT (sampling_interval); - interval = make_emacs_time (current_sampling_interval / billion, - current_sampling_interval % billion); + interval = make_timespec (current_sampling_interval / billion, + current_sampling_interval % billion); emacs_sigaction_init (&action, deliver_profiler_signal); sigaction (SIGPROF, &action, 0); diff --git a/src/sysdep.c b/src/sysdep.c index 0d732526528..e43991f41ab 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -306,7 +306,7 @@ get_child_status (pid_t child, int *status, int options, bool interruptible) /* If successful and status is requested, tell wait_reading_process_output that it needs to wake up and look around. */ if (pid && status && input_available_clear_time) - *input_available_clear_time = make_emacs_time (0, 0); + *input_available_clear_time = make_timespec (0, 0); return pid; } @@ -2021,8 +2021,8 @@ seed_random (void *seed, ptrdiff_t seed_size) void init_random (void) { - EMACS_TIME t = current_emacs_time (); - uintmax_t v = getpid () ^ EMACS_SECS (t) ^ EMACS_NSECS (t); + struct timespec t = current_timespec (); + uintmax_t v = getpid () ^ t.tv_sec ^ t.tv_nsec; seed_random (&v, sizeof v); } @@ -2357,7 +2357,7 @@ emacs_perror (char const *message) Use the least timeval not less than T. Return an extremal value if the result would overflow. */ struct timeval -make_timeval (EMACS_TIME t) +make_timeval (struct timespec t) { struct timeval tv; tv.tv_sec = t.tv_sec; @@ -2384,7 +2384,7 @@ make_timeval (EMACS_TIME t) If FD is nonnegative, then FILE can be NULL. */ int set_file_times (int fd, const char *filename, - EMACS_TIME atime, EMACS_TIME mtime) + struct timespec atime, struct timespec mtime) { struct timespec timespec[2]; timespec[0] = atime; @@ -2701,7 +2701,7 @@ list_system_processes (void) #endif /* !defined (WINDOWSNT) */ #if defined GNU_LINUX && defined HAVE_LONG_LONG_INT -static EMACS_TIME +static struct timespec time_from_jiffies (unsigned long long tval, long hz) { unsigned long long s = tval / hz; @@ -2710,34 +2710,34 @@ time_from_jiffies (unsigned long long tval, long hz) if (TYPE_MAXIMUM (time_t) < s) time_overflow (); - if (LONG_MAX - 1 <= ULLONG_MAX / EMACS_TIME_RESOLUTION - || frac <= ULLONG_MAX / EMACS_TIME_RESOLUTION) - ns = frac * EMACS_TIME_RESOLUTION / hz; + if (LONG_MAX - 1 <= ULLONG_MAX / TIMESPEC_RESOLUTION + || frac <= ULLONG_MAX / TIMESPEC_RESOLUTION) + ns = frac * TIMESPEC_RESOLUTION / hz; else { /* This is reachable only in the unlikely case that HZ * HZ exceeds ULLONG_MAX. It calculates an approximation that is guaranteed to be in range. */ - long hz_per_ns = (hz / EMACS_TIME_RESOLUTION - + (hz % EMACS_TIME_RESOLUTION != 0)); + long hz_per_ns = (hz / TIMESPEC_RESOLUTION + + (hz % TIMESPEC_RESOLUTION != 0)); ns = frac / hz_per_ns; } - return make_emacs_time (s, ns); + return make_timespec (s, ns); } static Lisp_Object ltime_from_jiffies (unsigned long long tval, long hz) { - EMACS_TIME t = time_from_jiffies (tval, hz); + struct timespec t = time_from_jiffies (tval, hz); return make_lisp_time (t); } -static EMACS_TIME +static struct timespec get_up_time (void) { FILE *fup; - EMACS_TIME up = make_emacs_time (0, 0); + struct timespec up = make_timespec (0, 0); block_input (); fup = emacs_fopen ("/proc/uptime", "r"); @@ -2755,18 +2755,18 @@ get_up_time (void) if (TYPE_MAXIMUM (time_t) < upsec) { upsec = TYPE_MAXIMUM (time_t); - upfrac = EMACS_TIME_RESOLUTION - 1; + upfrac = TIMESPEC_RESOLUTION - 1; } else { int upfraclen = upfrac_end - upfrac_start; - for (; upfraclen < LOG10_EMACS_TIME_RESOLUTION; upfraclen++) + for (; upfraclen < LOG10_TIMESPEC_RESOLUTION; upfraclen++) upfrac *= 10; - for (; LOG10_EMACS_TIME_RESOLUTION < upfraclen; upfraclen--) + for (; LOG10_TIMESPEC_RESOLUTION < upfraclen; upfraclen--) upfrac /= 10; - upfrac = min (upfrac, EMACS_TIME_RESOLUTION - 1); + upfrac = min (upfrac, TIMESPEC_RESOLUTION - 1); } - up = make_emacs_time (upsec, upfrac); + up = make_timespec (upsec, upfrac); } fclose (fup); } @@ -2887,7 +2887,7 @@ system_process_attributes (Lisp_Object pid) unsigned long long u_time, s_time, cutime, cstime, start; long priority, niceness, rss; unsigned long minflt, majflt, cminflt, cmajflt, vsize; - EMACS_TIME tnow, tstart, tboot, telapsed, us_time; + struct timespec tnow, tstart, tboot, telapsed, us_time; double pcpu, pmem; Lisp_Object attrs = Qnil; Lisp_Object cmd_str, decoded_cmd; @@ -3008,20 +3008,19 @@ system_process_attributes (Lisp_Object pid) attrs = Fcons (Fcons (Qnice, make_number (niceness)), attrs); attrs = Fcons (Fcons (Qthcount, make_fixnum_or_float (thcount)), attrs); - tnow = current_emacs_time (); + tnow = current_timespec (); telapsed = get_up_time (); - tboot = sub_emacs_time (tnow, telapsed); + tboot = timespec_sub (tnow, telapsed); tstart = time_from_jiffies (start, clocks_per_sec); - tstart = add_emacs_time (tboot, tstart); + tstart = timespec_add (tboot, tstart); attrs = Fcons (Fcons (Qstart, make_lisp_time (tstart)), attrs); attrs = Fcons (Fcons (Qvsize, make_fixnum_or_float (vsize / 1024)), attrs); attrs = Fcons (Fcons (Qrss, make_fixnum_or_float (4 * rss)), attrs); - telapsed = sub_emacs_time (tnow, tstart); + telapsed = timespec_sub (tnow, tstart); attrs = Fcons (Fcons (Qetime, make_lisp_time (telapsed)), attrs); us_time = time_from_jiffies (u_time + s_time, clocks_per_sec); - pcpu = (EMACS_TIME_TO_DOUBLE (us_time) - / EMACS_TIME_TO_DOUBLE (telapsed)); + pcpu = timespectod (us_time) / timespectod (telapsed); if (pcpu > 1.0) pcpu = 1.0; attrs = Fcons (Fcons (Qpcpu, make_float (100 * pcpu)), attrs); @@ -3239,16 +3238,16 @@ system_process_attributes (Lisp_Object pid) #elif defined __FreeBSD__ -static EMACS_TIME -timeval_to_EMACS_TIME (struct timeval t) +static struct timespec +timeval_to_timespec (struct timeval t) { - return make_emacs_time (t.tv_sec, t.tv_usec * 1000); + return make_timespec (t.tv_sec, t.tv_usec * 1000); } static Lisp_Object make_lisp_timeval (struct timeval t) { - return make_lisp_time (timeval_to_EMACS_TIME (t)); + return make_lisp_time (timeval_to_timespec (t)); } Lisp_Object @@ -3263,7 +3262,7 @@ system_process_attributes (Lisp_Object pid) char *ttyname; size_t len; char args[MAXPATHLEN]; - EMACS_TIME t, now; + struct timespec t, now; int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID}; struct kinfo_proc proc; @@ -3350,8 +3349,8 @@ system_process_attributes (Lisp_Object pid) attrs); attrs = Fcons (Fcons (Qstime, make_lisp_timeval (proc.ki_rusage.ru_stime)), attrs); - t = add_emacs_time (timeval_to_EMACS_TIME (proc.ki_rusage.ru_utime), - timeval_to_EMACS_TIME (proc.ki_rusage.ru_stime)); + t = timespec_add (timeval_to_timespec (proc.ki_rusage.ru_utime), + timeval_to_timespec (proc.ki_rusage.ru_stime)); attrs = Fcons (Fcons (Qtime, make_lisp_time (t)), attrs); attrs = Fcons (Fcons (Qcutime, @@ -3360,8 +3359,8 @@ system_process_attributes (Lisp_Object pid) attrs = Fcons (Fcons (Qcstime, make_lisp_timeval (proc.ki_rusage_ch.ru_utime)), attrs); - t = add_emacs_time (timeval_to_EMACS_TIME (proc.ki_rusage_ch.ru_utime), - timeval_to_EMACS_TIME (proc.ki_rusage_ch.ru_stime)); + t = timespec_add (timeval_to_timespec (proc.ki_rusage_ch.ru_utime), + timeval_to_timespec (proc.ki_rusage_ch.ru_stime)); attrs = Fcons (Fcons (Qctime, make_lisp_time (t)), attrs); attrs = Fcons (Fcons (Qthcount, make_fixnum_or_float (proc.ki_numthreads)), @@ -3373,8 +3372,8 @@ system_process_attributes (Lisp_Object pid) attrs = Fcons (Fcons (Qrss, make_number (proc.ki_rssize * pagesize >> 10)), attrs); - now = current_emacs_time (); - t = sub_emacs_time (now, timeval_to_EMACS_TIME (proc.ki_start)); + now = current_timespec (); + t = timespec_sub (now, timeval_to_timespec (proc.ki_start)); attrs = Fcons (Fcons (Qetime, make_lisp_time (t)), attrs); len = sizeof fscale; diff --git a/src/systime.h b/src/systime.h dissimilarity index 65% index df733b290c3..b1c3d940b0e 100644 --- a/src/systime.h +++ b/src/systime.h @@ -1,185 +1,101 @@ -/* systime.h - System-dependent definitions for time manipulations. - Copyright (C) 1993-1994, 2002-2013 Free Software Foundation, Inc. - -This file is part of GNU Emacs. - -GNU Emacs is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -GNU Emacs is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Emacs. If not, see . */ - -#ifndef EMACS_SYSTIME_H -#define EMACS_SYSTIME_H - -#include - -INLINE_HEADER_BEGIN -#ifndef SYSTIME_INLINE -# define SYSTIME_INLINE INLINE -#endif - -#ifdef emacs -# ifdef HAVE_X_WINDOWS -# include -# else -typedef unsigned long Time; -# endif -#endif - -/* On some configurations (hpux8.0, X11R4), sys/time.h and X11/Xos.h - disagree about the name of the guard symbol. */ -#ifdef HPUX -#ifdef _STRUCT_TIMEVAL -#ifndef __TIMEVAL__ -#define __TIMEVAL__ -#endif -#endif -#endif - -#include /* for 'struct timeval' */ - -/* The type to use to represent non-negative temporal intervals. Its - address can be passed as the timeout argument to the pselect system - call. */ -typedef struct timespec EMACS_TIME; - -/* Resolution of EMACS_TIME time stamps (in units per second), and log - base 10 of the resolution. The log must be a positive integer. */ -enum { EMACS_TIME_RESOLUTION = 1000000000 }; -enum { LOG10_EMACS_TIME_RESOLUTION = 9 }; - -/* EMACS_SECS (TIME) is the seconds component of TIME. - EMACS_NSECS (TIME) is the nanoseconds component of TIME. - emacs_secs_addr (PTIME) is the address of *PTIME's seconds component. */ -SYSTIME_INLINE time_t EMACS_SECS (EMACS_TIME t) { return t.tv_sec; } -SYSTIME_INLINE int EMACS_NSECS (EMACS_TIME t) { return t.tv_nsec; } -SYSTIME_INLINE time_t *emacs_secs_addr (EMACS_TIME *t) { return &t->tv_sec; } - -/* Return an Emacs time with seconds S and nanoseconds NS. */ -SYSTIME_INLINE EMACS_TIME -make_emacs_time (time_t s, int ns) -{ - EMACS_TIME r; - r.tv_sec = s; - r.tv_nsec = ns; - return r; -} - -/* Return an invalid Emacs time. */ -SYSTIME_INLINE EMACS_TIME -invalid_emacs_time (void) -{ - EMACS_TIME r; - r.tv_sec = 0; - r.tv_nsec = -1; - return r; -} - -/* Return current system time. */ -SYSTIME_INLINE EMACS_TIME -current_emacs_time (void) -{ - EMACS_TIME r; - gettime (&r); - return r; -} - -/* Return the result of adding A to B, or of subtracting B from A. - On overflow, store an extremal value: ergo, if time_t is unsigned, - return 0 if the true answer would be negative. - - WARNING: These are NOT general-purpose macros for adding or - subtracting arbitrary time values! They are generally intended to - be used with their first argument an absolute time since the epoch - and the second argument a non-negative offset. Do NOT use them for - anything else. */ -SYSTIME_INLINE EMACS_TIME -add_emacs_time (EMACS_TIME a, EMACS_TIME b) -{ - return timespec_add (a, b); -} -SYSTIME_INLINE EMACS_TIME -sub_emacs_time (EMACS_TIME a, EMACS_TIME b) -{ - return timespec_sub (a, b); -} - -/* Return the sign of the valid time stamp TIME, either -1, 0, or 1. - Note: this can only return a negative value if time_t is a signed - data type. */ -SYSTIME_INLINE int -EMACS_TIME_SIGN (EMACS_TIME t) -{ - return timespec_sign (t); -} - -/* Return 1 if TIME is a valid time stamp. */ -SYSTIME_INLINE int -EMACS_TIME_VALID_P (EMACS_TIME t) -{ - return t.tv_nsec >= 0; -} - -/* Convert the double D to the greatest EMACS_TIME not greater than D. - On overflow, return an extremal value; in particular, if time_t is - an unsigned data type and D is negative, return zero. Return the - minimum EMACS_TIME if D is not a number. */ -SYSTIME_INLINE EMACS_TIME -EMACS_TIME_FROM_DOUBLE (double d) -{ - return dtotimespec (d); -} - -/* Convert the Emacs time T to an approximate double value D. */ -SYSTIME_INLINE double -EMACS_TIME_TO_DOUBLE (EMACS_TIME t) -{ - return timespectod (t); -} - -/* defined in sysdep.c */ -extern int set_file_times (int, const char *, EMACS_TIME, EMACS_TIME); -extern struct timeval make_timeval (EMACS_TIME) ATTRIBUTE_CONST; - -/* defined in keyboard.c */ -extern void set_waiting_for_input (EMACS_TIME *); - -/* When lisp.h is not included Lisp_Object is not defined (this can - happen when this files is used outside the src directory). - Use GCPRO1 to determine if lisp.h was included. */ -#ifdef GCPRO1 -/* defined in editfns.c */ -extern Lisp_Object make_lisp_time (EMACS_TIME); -extern bool decode_time_components (Lisp_Object, Lisp_Object, Lisp_Object, - Lisp_Object, EMACS_TIME *, double *); -extern EMACS_TIME lisp_time_argument (Lisp_Object); -#endif - -/* Compare times T1 and T2 for equality, inequality etc. */ -SYSTIME_INLINE int -EMACS_TIME_EQ (EMACS_TIME t1, EMACS_TIME t2) -{ - return timespec_cmp (t1, t2) == 0; -} -SYSTIME_INLINE int -EMACS_TIME_LT (EMACS_TIME t1, EMACS_TIME t2) -{ - return timespec_cmp (t1, t2) < 0; -} -SYSTIME_INLINE int -EMACS_TIME_LE (EMACS_TIME t1, EMACS_TIME t2) -{ - return timespec_cmp (t1, t2) <= 0; -} - -INLINE_HEADER_END - -#endif /* EMACS_SYSTIME_H */ +/* systime.h - System-dependent definitions for time manipulations. + Copyright (C) 1993-1994, 2002-2013 Free Software Foundation, Inc. + +This file is part of GNU Emacs. + +GNU Emacs is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +GNU Emacs is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Emacs. If not, see . */ + +#ifndef EMACS_SYSTIME_H +#define EMACS_SYSTIME_H + +#include + +INLINE_HEADER_BEGIN +#ifndef SYSTIME_INLINE +# define SYSTIME_INLINE INLINE +#endif + +#ifdef emacs +# ifdef HAVE_X_WINDOWS +# include +# else +typedef unsigned long Time; +# endif +#endif + +/* On some configurations (hpux8.0, X11R4), sys/time.h and X11/Xos.h + disagree about the name of the guard symbol. */ +#ifdef HPUX +#ifdef _STRUCT_TIMEVAL +#ifndef __TIMEVAL__ +#define __TIMEVAL__ +#endif +#endif +#endif + +#include /* for 'struct timeval' */ + +/* Emacs uses struct timespec to represent nonnegative temporal intervals. + + WARNING: Since tv_sec might be an unsigned value, do not use struct + timespec as a general-purpose data type for adding or subtracting + arbitrary time values! When computing A + B or A - B, typically A + should be an absolute time since the epoch and B a nonnegative offset. */ + +/* Return an invalid timespec. */ +SYSTIME_INLINE struct timespec +invalid_timespec (void) +{ + return make_timespec (0, -1); +} + +/* Return 1 if TIME is a valid timespec. This currently doesn't worry + about whether tv_nsec is less than TIMESPEC_RESOLUTION; leap seconds + might cause a problem if it did. */ +SYSTIME_INLINE int +timespec_valid_p (struct timespec t) +{ + return t.tv_nsec >= 0; +} + +/* Return current system time. */ +SYSTIME_INLINE struct timespec +current_timespec (void) +{ + struct timespec r; + gettime (&r); + return r; +} + +/* defined in sysdep.c */ +extern int set_file_times (int, const char *, struct timespec, struct timespec); +extern struct timeval make_timeval (struct timespec) ATTRIBUTE_CONST; + +/* defined in keyboard.c */ +extern void set_waiting_for_input (struct timespec *); + +/* When lisp.h is not included Lisp_Object is not defined (this can + happen when this files is used outside the src directory). + Use GCPRO1 to determine if lisp.h was included. */ +#ifdef GCPRO1 +/* defined in editfns.c */ +extern Lisp_Object make_lisp_time (struct timespec); +extern bool decode_time_components (Lisp_Object, Lisp_Object, Lisp_Object, + Lisp_Object, struct timespec *, double *); +extern struct timespec lisp_time_argument (Lisp_Object); +#endif + +INLINE_HEADER_END + +#endif /* EMACS_SYSTIME_H */ diff --git a/src/w32.c b/src/w32.c index 7f9b96a77a5..05a3fde97ce 100644 --- a/src/w32.c +++ b/src/w32.c @@ -247,7 +247,7 @@ static BOOL WINAPI revert_to_self (void); extern int sys_access (const char *, int); extern void *e_malloc (size_t); extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *, - EMACS_TIME *, void *); + struct timespec *, void *); extern int sys_dup (int); @@ -7939,7 +7939,7 @@ emacs_gnutls_pull (gnutls_transport_ptr_t p, void* buf, size_t sz) { int n, err; SELECT_TYPE fdset; - EMACS_TIME timeout; + struct timespec timeout; struct Lisp_Process *process = (struct Lisp_Process *)p; int fd = process->infd; diff --git a/src/w32proc.c b/src/w32proc.c index 84589388cd7..54316a6f80f 100644 --- a/src/w32proc.c +++ b/src/w32proc.c @@ -1916,7 +1916,7 @@ extern int proc_buffered_char[]; int sys_select (int nfds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, - EMACS_TIME *timeout, void *ignored) + struct timespec *timeout, void *ignored) { SELECT_TYPE orfds; DWORD timeout_ms, start_time; diff --git a/src/xdisp.c b/src/xdisp.c index 98ff1aae1d8..46992d2f396 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -29800,20 +29800,20 @@ void start_hourglass (void) { #if defined (HAVE_WINDOW_SYSTEM) - EMACS_TIME delay; + struct timespec delay; cancel_hourglass (); if (INTEGERP (Vhourglass_delay) && XINT (Vhourglass_delay) > 0) - delay = make_emacs_time (min (XINT (Vhourglass_delay), + delay = make_timespec (min (XINT (Vhourglass_delay), TYPE_MAXIMUM (time_t)), - 0); + 0); else if (FLOATP (Vhourglass_delay) && XFLOAT_DATA (Vhourglass_delay) > 0) - delay = EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay)); + delay = dtotimespec (XFLOAT_DATA (Vhourglass_delay)); else - delay = make_emacs_time (DEFAULT_HOURGLASS_DELAY, 0); + delay = make_timespec (DEFAULT_HOURGLASS_DELAY, 0); #ifdef HAVE_NTGUI { diff --git a/src/xgselect.c b/src/xgselect.c index 97f53373b63..45a34f2e0a5 100644 --- a/src/xgselect.c +++ b/src/xgselect.c @@ -25,15 +25,16 @@ along with GNU Emacs. If not, see . */ #include #include +#include #include "frame.h" int xg_select (int fds_lim, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, - EMACS_TIME const *timeout, sigset_t const *sigmask) + struct timespec const *timeout, sigset_t const *sigmask) { SELECT_TYPE all_rfds, all_wfds; - EMACS_TIME tmo; - EMACS_TIME const *tmop = timeout; + struct timespec tmo; + struct timespec const *tmop = timeout; GMainContext *context; int have_wfds = wfds != NULL; @@ -86,9 +87,9 @@ xg_select (int fds_lim, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, if (tmo_in_millisec >= 0) { - tmo = make_emacs_time (tmo_in_millisec / 1000, - 1000 * 1000 * (tmo_in_millisec % 1000)); - if (!timeout || EMACS_TIME_LT (tmo, *timeout)) + tmo = make_timespec (tmo_in_millisec / 1000, + 1000 * 1000 * (tmo_in_millisec % 1000)); + if (!timeout || timespec_cmp (tmo, *timeout) < 0) tmop = &tmo; } diff --git a/src/xgselect.h b/src/xgselect.h index 21c8acf1016..f85c17f7190 100644 --- a/src/xgselect.h +++ b/src/xgselect.h @@ -21,14 +21,14 @@ along with GNU Emacs. If not, see . */ #define XGSELECT_H #include "lisp.h" -#include "systime.h" +#include #include "sysselect.h" extern int xg_select (int max_fds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, - EMACS_TIME const *timeout, + struct timespec const *timeout, sigset_t const *sigmask); #endif /* XGSELECT_H */ diff --git a/src/xmenu.c b/src/xmenu.c index 95ae5393553..98473939373 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -377,7 +377,7 @@ x_menu_wait_for_event (void *data) #endif ) { - EMACS_TIME next_time = timer_check (), *ntp; + struct timespec next_time = timer_check (), *ntp; SELECT_TYPE read_fds; struct x_display_info *dpyinfo; int n = 0; @@ -391,7 +391,7 @@ x_menu_wait_for_event (void *data) XFlush (dpyinfo->display); } - if (! EMACS_TIME_VALID_P (next_time)) + if (! timespec_valid_p (next_time)) ntp = 0; else ntp = &next_time; diff --git a/src/xterm.c b/src/xterm.c index 7014bdb9740..5a67c3b6f2f 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -3112,22 +3112,22 @@ XTflash (struct frame *f) x_flush (f); { - EMACS_TIME delay = make_emacs_time (0, 150 * 1000 * 1000); - EMACS_TIME wakeup = add_emacs_time (current_emacs_time (), delay); + struct timespec delay = make_timespec (0, 150 * 1000 * 1000); + struct timespec wakeup = timespec_add (current_timespec (), delay); /* Keep waiting until past the time wakeup or any input gets available. */ while (! detect_input_pending ()) { - EMACS_TIME current = current_emacs_time (); - EMACS_TIME timeout; + struct timespec current = current_timespec (); + struct timespec timeout; /* Break if result would not be positive. */ - if (EMACS_TIME_LE (wakeup, current)) + if (timespec_cmp (wakeup, current) <= 0) break; /* How long `select' should wait. */ - timeout = make_emacs_time (0, 10 * 1000 * 1000); + timeout = make_timespec (0, 10 * 1000 * 1000); /* Try to wait that long--but we might wake up sooner. */ pselect (0, NULL, NULL, NULL, &timeout, NULL); @@ -8677,7 +8677,7 @@ x_wait_for_event (struct frame *f, int eventtype) int level = interrupt_input_blocked; SELECT_TYPE fds; - EMACS_TIME tmo, tmo_at, time_now; + struct timespec tmo, tmo_at, time_now; int fd = ConnectionNumber (FRAME_X_DISPLAY (f)); pending_event_wait.f = f; @@ -8685,8 +8685,8 @@ x_wait_for_event (struct frame *f, int eventtype) /* Set timeout to 0.1 second. Hopefully not noticeable. Maybe it should be configurable. */ - tmo = make_emacs_time (0, 100 * 1000 * 1000); - tmo_at = add_emacs_time (current_emacs_time (), tmo); + tmo = make_timespec (0, 100 * 1000 * 1000); + tmo_at = timespec_add (current_timespec (), tmo); while (pending_event_wait.eventtype) { @@ -8699,11 +8699,11 @@ x_wait_for_event (struct frame *f, int eventtype) FD_ZERO (&fds); FD_SET (fd, &fds); - time_now = current_emacs_time (); - if (EMACS_TIME_LT (tmo_at, time_now)) + time_now = current_timespec (); + if (timespec_cmp (tmo_at, time_now) < 0) break; - tmo = sub_emacs_time (tmo_at, time_now); + tmo = timespec_sub (tmo_at, time_now); if (pselect (fd + 1, &fds, NULL, NULL, &tmo, NULL) == 0) break; /* Timeout */ } @@ -10425,7 +10425,7 @@ x_activate_timeout_atimer (void) block_input (); if (!x_timeout_atimer_activated_flag) { - EMACS_TIME interval = make_emacs_time (0, 100 * 1000 * 1000); + struct timespec interval = make_timespec (0, 100 * 1000 * 1000); start_atimer (ATIMER_RELATIVE, interval, x_process_timeouts, 0); x_timeout_atimer_activated_flag = 1; } -- 2.11.4.GIT