[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/3] gethrxtime: better 'inline'
From: |
Paul Eggert |
Subject: |
[PATCH 1/3] gethrxtime: better 'inline' |
Date: |
Tue, 30 Oct 2012 11:08:25 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121016 Thunderbird/16.0.1 |
[Today I have three more proposed patches re 'inline'.
The 3rd one affects Bruno's modules exclusively
and I'll CC: that message to Bruno.]
* 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.o.
---
ChangeLog | 22 ++++++++++++++++++++++
lib/gethrxtime.c | 19 ++++++++++++-------
lib/gethrxtime.h | 19 +++++++++++++------
lib/xtime.c | 3 +++
lib/xtime.h | 35 ++++++++++++++++++++---------------
m4/gethrxtime.m4 | 16 +++++-----------
modules/gethrxtime | 7 +++----
7 files changed, 78 insertions(+), 43 deletions(-)
create mode 100644 lib/xtime.c
diff --git a/ChangeLog b/ChangeLog
index 94caadc..ebf5c5c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2012-10-29 Paul Eggert <address@hidden>
+
+ 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.o.
+
2012-10-28 Paul Eggert <address@hidden>
wctype-h: better 'inline'
diff --git a/lib/gethrxtime.c b/lib/gethrxtime.c
index 6e0263d..bd0628a 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
diff --git a/lib/gethrxtime.h b/lib/gethrxtime.h
index 9453d60..1b81527 100644
--- a/lib/gethrxtime.h
+++ b/lib/gethrxtime.h
@@ -18,9 +18,14 @@
/* Written by Paul Eggert. */
#ifndef GETHRXTIME_H_
-# define GETHRXTIME_H_ 1
+#define GETHRXTIME_H_ 1
-# include "xtime.h"
+#include "xtime.h"
+
+_GL_INLINE_HEADER_BEGIN
+#ifndef GETHRXTIME_INLINE
+# define GETHRXTIME_INLINE _GL_INLINE
+#endif
#ifdef __cplusplus
extern "C" {
@@ -31,12 +36,14 @@ extern "C" {
high-resolution clock that is not subject to resetting or
drifting. */
-# if HAVE_ARITHMETIC_HRTIME_T && HAVE_DECL_GETHRTIME
-# include <time.h>
-static inline xtime_t gethrxtime (void) { return gethrtime (); }
+#if HAVE_ARITHMETIC_HRTIME_T && HAVE_DECL_GETHRTIME
+# include <time.h>
+GETHRXTIME_INLINE xtime_t gethrxtime (void) { return gethrtime (); }
# else
xtime_t gethrxtime (void);
-# endif
+#endif
+
+_GL_INLINE_HEADER_END
#ifdef __cplusplus
}
diff --git a/lib/xtime.c b/lib/xtime.c
new file mode 100644
index 0000000..e608f69
--- /dev/null
+++ b/lib/xtime.c
@@ -0,0 +1,3 @@
+#include <config.h>
+#define XTIME_INLINE _GL_EXTERN_INLINE
+#include "xtime.h"
diff --git a/lib/xtime.h b/lib/xtime.h
index 3d235fa..544841f 100644
--- a/lib/xtime.h
+++ b/lib/xtime.h
@@ -18,24 +18,29 @@
/* Written by Paul Eggert. */
#ifndef XTIME_H_
-# define XTIME_H_ 1
+#define XTIME_H_ 1
+
+_GL_INLINE_HEADER_BEGIN
+#ifndef XTIME_INLINE
+# define XTIME_INLINE _GL_INLINE
+#endif
/* xtime_t is a signed type used for time stamps. It is an integer
type that is a count of nanoseconds -- except for obsolescent hosts
without sufficiently-wide integers, where it is a count of
seconds. */
-# if HAVE_LONG_LONG_INT
+#if HAVE_LONG_LONG_INT
typedef long long int xtime_t;
-# define XTIME_PRECISION 1000000000
-# else
-# include <limits.h>
+# define XTIME_PRECISION 1000000000
+#else
+# include <limits.h>
typedef long int xtime_t;
-# if LONG_MAX >> 31 >> 31 == 0
-# define XTIME_PRECISION 1
-# else
-# define XTIME_PRECISION 1000000000
-# endif
+# if LONG_MAX >> 31 >> 31 == 0
+# define XTIME_PRECISION 1
+# else
+# define XTIME_PRECISION 1000000000
# endif
+#endif
#ifdef __cplusplus
extern "C" {
@@ -43,7 +48,7 @@ extern "C" {
/* Return an extended time value that contains S seconds and NS
nanoseconds, without any overflow checking. */
-static inline xtime_t
+XTIME_INLINE xtime_t
xtime_make (xtime_t s, long int ns)
{
if (XTIME_PRECISION == 1)
@@ -53,14 +58,14 @@ xtime_make (xtime_t s, long int ns)
}
/* Return the number of seconds in T, which must be nonnegative. */
-static inline xtime_t
+XTIME_INLINE xtime_t
xtime_nonnegative_sec (xtime_t t)
{
return t / XTIME_PRECISION;
}
/* Return the number of seconds in T. */
-static inline xtime_t
+XTIME_INLINE xtime_t
xtime_sec (xtime_t t)
{
return (XTIME_PRECISION == 1
@@ -71,14 +76,14 @@ xtime_sec (xtime_t t)
}
/* Return the number of nanoseconds in T, which must be nonnegative. */
-static inline long int
+XTIME_INLINE long int
xtime_nonnegative_nsec (xtime_t t)
{
return t % XTIME_PRECISION;
}
/* Return the number of nanoseconds in T. */
-static inline long int
+XTIME_INLINE long int
xtime_nsec (xtime_t t)
{
long int ns = t % XTIME_PRECISION;
diff --git a/m4/gethrxtime.m4 b/m4/gethrxtime.m4
index 6a54ee0..bab2e00 100644
--- a/m4/gethrxtime.m4
+++ b/m4/gethrxtime.m4
@@ -1,4 +1,4 @@
-# gethrxtime.m4 serial 11
+# gethrxtime.m4 serial 12
dnl Copyright (C) 2005-2006, 2008-2012 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -18,8 +18,10 @@ AC_DEFUN([gl_GETHRXTIME],
dnl Find libraries needed to link lib/gethrxtime.c.
AC_REQUIRE([gl_CLOCK_TIME])
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
- AC_CHECK_FUNCS_ONCE([nanouptime])
- if test $ac_cv_func_nanouptime != yes; then
+ AC_CHECK_FUNCS_ONCE([microuptime nanouptime])
+ if test $ac_cv_func_nanouptime != yes \
+ && { test $ac_cv_have_decl_gethrtime = no \
+ || test $gl_cv_arithmetic_hrtime_t = no; }; then
AC_CACHE_CHECK([whether CLOCK_MONOTONIC or CLOCK_REALTIME is defined],
[gl_cv_have_clock_gettime_macro],
[AC_EGREP_CPP([have_clock_gettime_macro],
@@ -60,14 +62,6 @@ AC_DEFUN([gl_ARITHMETIC_HRTIME_T],
# Prerequisites of lib/xtime.h.
AC_DEFUN([gl_XTIME],
[
- AC_REQUIRE([AC_C_INLINE])
AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
:
])
-
-# Prerequisites of lib/gethrxtime.c.
-AC_DEFUN([gl_PREREQ_GETHRXTIME],
-[
- AC_CHECK_FUNCS_ONCE([microuptime])
- :
-])
diff --git a/modules/gethrxtime b/modules/gethrxtime
index 916bab1..8922321 100644
--- a/modules/gethrxtime
+++ b/modules/gethrxtime
@@ -3,6 +3,7 @@ Get high resolution real time.
Files:
lib/xtime.h
+lib/xtime.c
lib/gethrxtime.c
lib/gethrxtime.h
m4/gethrxtime.m4
@@ -11,17 +12,15 @@ m4/longlong.m4
Depends-on:
clock-time
extensions
+extern-inline
gettime
sys_time
configure.ac:
gl_GETHRXTIME
-if test $ac_cv_have_decl_gethrtime = no || test $gl_cv_arithmetic_hrtime_t =
no; then
- AC_LIBOBJ([gethrxtime])
- gl_PREREQ_GETHRXTIME
-fi
Makefile.am:
+lib_SOURCES += gethrxtime.o xtime.c
Include:
"xtime.h"
--
1.7.11.7
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH 1/3] gethrxtime: better 'inline',
Paul Eggert <=