Skip to content
Snippets Groups Projects
Commit aea80ca3 authored by Russell Bryant's avatar Russell Bryant
Browse files

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: https://origsvn.digium.com/svn/asterisk/trunk@94029 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 5e84c055
No related branches found
No related tags found
No related merge requests found
...@@ -36,6 +36,39 @@ extern struct timeval tv; ...@@ -36,6 +36,39 @@ extern struct timeval tv;
typedef typeof(tv.tv_sec) ast_time_t; typedef typeof(tv.tv_sec) ast_time_t;
typedef typeof(tv.tv_usec) ast_suseconds_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. * \brief Computes the difference (in milliseconds) between two \c struct \c timeval instances.
* \param end end of the time period * \param end end of the time period
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment