[svn-commits] russell: trunk r94029 - /trunk/include/asterisk/time.h
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Wed Dec 19 13:29:15 CST 2007
Author: russell
Date: Wed Dec 19 13:29:14 2007
New Revision: 94029
URL: http://svn.digium.com/view/asterisk?view=rev&rev=94029
Log:
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)
Modified:
trunk/include/asterisk/time.h
Modified: trunk/include/asterisk/time.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/time.h?view=diff&rev=94029&r1=94028&r2=94029
==============================================================================
--- trunk/include/asterisk/time.h (original)
+++ trunk/include/asterisk/time.h Wed Dec 19 13:29:14 2007
@@ -35,6 +35,39 @@
extern struct timeval tv;
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.
More information about the svn-commits
mailing list