diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2018-09-16 21:24:04 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2018-09-16 21:28:08 -0700 |
commit | 295bacba61bd681798b55599551116db197b3388 (patch) | |
tree | 167fe2864edc58f5f847c6a64133ad3463201986 /lib | |
parent | 75ab41d00d97c4de1ca343ce5273d1aad4975f37 (diff) | |
download | emacs-295bacba61bd681798b55599551116db197b3388.tar.gz |
Move current_timespec decl to timespec.h
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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gettime.c | 29 | ||||
-rw-r--r-- | lib/timespec.h | 10 |
2 files changed, 22 insertions, 17 deletions
diff --git a/lib/gettime.c b/lib/gettime.c index 9a4e342f18e..171f22476f8 100644 --- a/lib/gettime.c +++ b/lib/gettime.c @@ -28,21 +28,24 @@ 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; } diff --git a/lib/timespec.h b/lib/timespec.h index c414cfe45ee..cc49668f42a 100644 --- a/lib/timespec.h +++ b/lib/timespec.h @@ -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 } |