]> git.eshelyaron.com Git - emacs.git/commitdiff
Move current_timespec decl to timespec.h
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 17 Sep 2018 04:24:04 +0000 (21:24 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 17 Sep 2018 04:28:08 +0000 (21:28 -0700)
This change was motivated by the desire to remove the weird
dependency of lib-src/profile.o on src/systime.h.  profile.c
included systime.h only for current_timespec, and this
inclusion required systime.h to have #ifdef emacs in multiple
places and complicated further changes I have in mind.
The current_timespec decl belongs in timespec.h anyway,
and the main effect of this change is to move it there.
* lib-src/profile.c (INLINE): Remove.
Include timespec.h, not systime.h.
* lib/gettime.c (gettime): Prefer clock_gettime to nanotime,
and don’t worry about it failing on a CLOCK_REALTIME arg.
POSIX requires it to succeed and I don’t know of any
counterexamples where the fallbacks would work.
(current_timespec): Move here from src/systime.h.
Nowadays it seems to be better to not have this function
be inline.
* lib/timespec.h: Include arg-nonnull.h.
(current_timespec): New declaration.
(gettime, settime): Declare args to be nonnull.
* lib/gettime.c, lib/timespec.h: Copy from Gnulib.
* src/systime.h: Simplify by assuming ‘emacs’ is defined,
which it always is now.
(current_timespec): Move to lib/timespec.h.

lib-src/profile.c
lib/gettime.c
lib/timespec.h
src/systime.h

index cccdfbc7c84aa7caf95bd562ce7e19cc0f1288ed..649eb04b3749d2b7ae551a22603708332fc9f6f4 100644 (file)
@@ -30,14 +30,13 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
  **  operations: reset_watch, get_time
  */
 
-#define INLINE EXTERN_INLINE
 #include <config.h>
 
 #include <inttypes.h>
 #include <stdlib.h>
 
 #include <intprops.h>
-#include <systime.h>
+#include <timespec.h>
 #include <unlocked-io.h>
 
 static struct timespec TV1;
index 9a4e342f18e0cd8a7a922988c9fc0f88baf57f25..171f22476f899eadef562f8efef20a80ced67f55 100644 (file)
 void
 gettime (struct timespec *ts)
 {
-#if HAVE_NANOTIME
+#if defined CLOCK_REALTIME && HAVE_CLOCK_GETTIME
+  clock_gettime (CLOCK_REALTIME, ts);
+#elif HAVE_NANOTIME
   nanotime (ts);
 #else
+  struct timeval tv;
+  gettimeofday (&tv, NULL);
+  ts->tv_sec = tv.tv_sec;
+  ts->tv_nsec = tv.tv_usec * 1000;
+#endif
+}
 
-# if defined CLOCK_REALTIME && HAVE_CLOCK_GETTIME
-  if (clock_gettime (CLOCK_REALTIME, ts) == 0)
-    return;
-# endif
-
-  {
-    struct timeval tv;
-    gettimeofday (&tv, NULL);
-    ts->tv_sec = tv.tv_sec;
-    ts->tv_nsec = tv.tv_usec * 1000;
-  }
+/* Return the current system time as a struct timespec.  */
 
-#endif
+struct timespec
+current_timespec (void)
+{
+  struct timespec ts;
+  gettime (&ts);
+  return ts;
 }
index c414cfe45ee9359472e23b4b202efccce66c5a33..cc49668f42a6d455e3c556be97293854445e6aaf 100644 (file)
@@ -17,9 +17,9 @@
    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
 
 #if ! defined TIMESPEC_H
-# define TIMESPEC_H
+#define TIMESPEC_H
 
-# include <time.h>
+#include <time.h>
 
 #ifndef _GL_INLINE_HEADER_BEGIN
  #error "Please include config.h first."
@@ -33,6 +33,7 @@ _GL_INLINE_HEADER_BEGIN
 extern "C" {
 #endif
 
+#include "arg-nonnull.h"
 #include "verify.h"
 
 /* Inverse resolution of timespec timestamps (in units per second),
@@ -122,8 +123,9 @@ timespectod (struct timespec a)
   return a.tv_sec + a.tv_nsec / 1e9;
 }
 
-void gettime (struct timespec *);
-int settime (struct timespec const *);
+struct timespec current_timespec (void);
+void gettime (struct timespec *) _GL_ARG_NONNULL ((1));
+int settime (struct timespec const *) _GL_ARG_NONNULL ((1));
 
 #ifdef __cplusplus
 }
index ede3d4eb12d08c435737436cc5372606ae07fd4d..ad5ab8573080814c3292cad0e863d77b087bde89 100644 (file)
@@ -23,12 +23,10 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
 
 INLINE_HEADER_BEGIN
 
-#ifdef emacs
-# ifdef HAVE_X_WINDOWS
-#  include <X11/X.h>
-# else
+#ifdef HAVE_X_WINDOWS
+# include <X11/X.h>
+#else
 typedef unsigned long Time;
-# endif
 #endif
 
 /* On some configurations (hpux8.0, X11R4), sys/time.h and X11/Xos.h
@@ -66,15 +64,6 @@ timespec_valid_p (struct timespec t)
   return t.tv_nsec >= 0;
 }
 
-/* Return current system time.  */
-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;
@@ -82,10 +71,6 @@ 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 file is used outside the src directory).  */
-#ifdef emacs
-
 /* Emacs uses the integer list (HI LO US PS) to represent the time
    (HI << LO_TIME_BITS) + LO + US / 1e6 + PS / 1e12.  */
 enum { LO_TIME_BITS = 16 };
@@ -103,7 +88,6 @@ extern int decode_time_components (Lisp_Object, Lisp_Object, Lisp_Object,
                                   Lisp_Object, struct lisp_time *, double *);
 extern struct timespec lisp_to_timespec (struct lisp_time);
 extern struct timespec lisp_time_argument (Lisp_Object);
-#endif
 
 INLINE_HEADER_END