summaryrefslogtreecommitdiff
path: root/lib/gethrxtime.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2012-11-20 22:25:07 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2012-11-29 23:38:52 -0800
commit691d7bd0ad1d0ba169776bc9ab6a983a8201848e (patch)
tree582b29c6e9bdc7bd28e6c2b7910dfcf3aadb6639 /lib/gethrxtime.c
parent15b55826727e2010405953a370da01c59ab9ea0d (diff)
downloadgnulib-691d7bd0ad1d0ba169776bc9ab6a983a8201848e.tar.gz
gethrxtime: better 'inline'
* lib/xtime.c: New file. * lib/gethrxtime.c, lib/gethrxtime.h (GETHRXTIME_INLINE): * lib/xtime.h (XTIME_INCLUDE): New macros. Replace all uses of 'static inline' with them. * lib/gethrxtime.c (gethrxtime): Define only if ! (HAVE_ARITHMETIC_HRTIME_T && HAVE_DECL_GETHRTIME), since this source file is now always compiled, because of the extern inline. * lib/gethrxtime.h, lib/xtime.h: Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END. * m4/gethrxtime.m4 (gl_GETHRXTIME): Do not check for clock macros if gethrtime works, as they're not needed in that case. (gl_XTIME): Do not require AC_C_INLINE. (gl_PREREQ_GETHRXTIME): Remove; all uses removed, as it's always compiled now. Move the check into gl_GETHRXTIME. * modules/gethrxtime (Files, lib_SOURCES): Add lib/xtime.c. (Depends-on): Add extern-inline. (configure.ac): gethrxtime is always compiled now. (lib_SOURCES): Add gethrxtime.c.
Diffstat (limited to 'lib/gethrxtime.c')
-rw-r--r--lib/gethrxtime.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/gethrxtime.c b/lib/gethrxtime.c
index 6e0263d6f0..bd0628a1cf 100644
--- a/lib/gethrxtime.c
+++ b/lib/gethrxtime.c
@@ -19,8 +19,11 @@
#include <config.h>
+#define GETHRXTIME_INLINE _GL_EXTERN_INLINE
#include "gethrxtime.h"
+#if ! (HAVE_ARITHMETIC_HRTIME_T && HAVE_DECL_GETHRTIME)
+
#include <sys/time.h>
#include "timespec.h"
@@ -32,30 +35,30 @@
xtime_t
gethrxtime (void)
{
-#if HAVE_NANOUPTIME
+# if HAVE_NANOUPTIME
{
struct timespec ts;
nanouptime (&ts);
return xtime_make (ts.tv_sec, ts.tv_nsec);
}
-#else
+# else
-# if defined CLOCK_MONOTONIC && HAVE_CLOCK_GETTIME
+# if defined CLOCK_MONOTONIC && HAVE_CLOCK_GETTIME
{
struct timespec ts;
if (clock_gettime (CLOCK_MONOTONIC, &ts) == 0)
return xtime_make (ts.tv_sec, ts.tv_nsec);
}
-# endif
+# endif
-# if HAVE_MICROUPTIME
+# if HAVE_MICROUPTIME
{
struct timeval tv;
microuptime (&tv);
return xtime_make (tv.tv_sec, 1000 * tv.tv_usec);
}
-# else
+# else
/* No monotonically increasing clocks are available; fall back on a
clock that might jump backwards, since it's the best we can do. */
{
@@ -63,6 +66,8 @@ gethrxtime (void)
gettime (&ts);
return xtime_make (ts.tv_sec, ts.tv_nsec);
}
+# endif
# endif
-#endif
}
+
+#endif