diff options
author | Joshua Colp <jcolp@digium.com> | 2015-08-10 11:27:12 -0500 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2015-08-10 11:27:12 -0500 |
commit | ff36b5482b05baa3e91161c567162873d7d2b38d (patch) | |
tree | b9b57dfed43e662eef99bf340f1765acd612d114 /include/asterisk | |
parent | 35fe8f74fe680ab2e9b41149762559e3ea02bfa9 (diff) | |
parent | 40caf0ad9bef07bdfb568a88192c157dd1840100 (diff) |
Merge "Replaces clock_gettime() with ast_tsnow()"
Diffstat (limited to 'include/asterisk')
-rw-r--r-- | include/asterisk/autoconfig.h.in | 3 | ||||
-rw-r--r-- | include/asterisk/time.h | 34 |
2 files changed, 37 insertions, 0 deletions
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in index 965b329de..17aac1d83 100644 --- a/include/asterisk/autoconfig.h.in +++ b/include/asterisk/autoconfig.h.in @@ -767,6 +767,9 @@ /* Define to 1 if you have the `roundl' function. */ #undef HAVE_ROUNDL +/* Define to 1 if rt has the Realtime functions feature. */ +#undef HAVE_RT + /* Define if your system has the RTLD_NOLOAD headers. */ #undef HAVE_RTLD_NOLOAD diff --git a/include/asterisk/time.h b/include/asterisk/time.h index f2382df33..529490630 100644 --- a/include/asterisk/time.h +++ b/include/asterisk/time.h @@ -23,10 +23,16 @@ #ifndef _ASTERISK_TIME_H #define _ASTERISK_TIME_H +#include "asterisk/autoconfig.h" + #ifdef HAVE_SYS_TIME_H #include <sys/time.h> #endif +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif + #include "asterisk/inline_api.h" /* We have to let the compiler learn what types to use for the elements of a @@ -142,6 +148,34 @@ struct timeval ast_tvnow(void), ) /*! + * \brief Returns current timespec. Meant to avoid calling ast_tvnow() just to + * create a timespec from the timeval it returns. + */ +#if defined _POSIX_TIMERS && _POSIX_TIMERS > 0 +AST_INLINE_API( +struct timespec ast_tsnow(void), +{ + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + return ts; +} +) +#else +AST_INLINE_API( +struct timespec ast_tsnow(void), +{ + struct timeval tv = ast_tvnow(); + struct timespec ts; + /* Can't use designated initializer, because it does odd things with + * the AST_INLINE_API macro. Go figure. */ + ts.tv_sec = tv.tv_sec; + ts.tv_nsec = tv.tv_usec * 1000; + return ts; +} +) +#endif + +/*! * \brief Returns the sum of two timevals a + b */ struct timeval ast_tvadd(struct timeval a, struct timeval b); |