diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-12-19 19:29:14 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-12-19 19:29:14 +0000 |
commit | 6a7bc1cd99390a8248591d7c8f41188456ddbad8 (patch) | |
tree | ffb2aebb54322c9ab28b261fa4bb754e394be221 /include | |
parent | f1c01a6797fbba5a02641b9cc79d0c130ea328ac (diff) |
Add a couple of new time API calls - ast_tvdiff_sec and ast_tvdiff_usec
(closes issue #11270)
Reported by: dimas
Patches:
tvdiff_us-4.patch uploaded by dimas (license 88)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@94029 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include')
-rw-r--r-- | include/asterisk/time.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/include/asterisk/time.h b/include/asterisk/time.h index 3b94cd646..4b7ca00ff 100644 --- a/include/asterisk/time.h +++ b/include/asterisk/time.h @@ -37,6 +37,39 @@ typedef typeof(tv.tv_sec) ast_time_t; typedef typeof(tv.tv_usec) ast_suseconds_t; /*! + * \brief Computes the difference (in seconds) between two \c struct \c timeval instances. + * \param end the end of the time period + * \param start the beginning of the time period + * \return the difference in seconds + */ +AST_INLINE_API( +int ast_tvdiff_sec(struct timeval end, struct timeval start), +{ + int result = end.tv_sec - start.tv_sec; + if (result > 0 && end.tv_usec < start.tv_usec) + result--; + else if (result < 0 && end.tv_usec > start.tv_usec) + result++; + + return result; +} +) + +/*! + * \brief Computes the difference (in microseconds) between two \c struct \c timeval instances. + * \param end the end of the time period + * \param start the beginning of the time period + * \return the difference in microseconds + */ +AST_INLINE_API( +int64_t ast_tvdiff_us(struct timeval end, struct timeval start), +{ + return (end.tv_sec - start.tv_sec) * (int64_t) 1000000 + + end.tv_usec - start.tv_usec; +} +) + +/*! * \brief Computes the difference (in milliseconds) between two \c struct \c timeval instances. * \param end end of the time period * \param start beginning of the time period |