diff options
author | Mark Michelson <mmichelson@digium.com> | 2012-11-07 19:15:26 +0000 |
---|---|---|
committer | Mark Michelson <mmichelson@digium.com> | 2012-11-07 19:15:26 +0000 |
commit | f2bb9afe17ee3e321a2d853dbfed4a93a67c25ca (patch) | |
tree | e86066d0a7b10defce1f17b3e2038527555f92e9 /include/asterisk | |
parent | 6ad0126425993bd9c9c73b0c05a52984cbcadc5d (diff) |
Multiple revisions 375993-375994
........
r375993 | mmichelson | 2012-11-07 11:01:13 -0600 (Wed, 07 Nov 2012) | 30 lines
Fix misuses of timeouts throughout the code.
Prior to this change, a common method for determining if a timeout
was reached was to call a function such as ast_waitfor_n() and inspect
the out parameter that told how many milliseconds were left, then use
that as the input to ast_waitfor_n() on the next go-around.
The problem with this is that in some cases, submillisecond timeouts
can occur, resulting in the out parameter not decreasing any. When this
happens thousands of times, the result is that the timeout takes much
longer than intended to be reached. As an example, I had a situation where
a 3 second timeout took multiple days to finally end since most wakeups
from ast_waitfor_n() were under a millisecond.
This patch seeks to fix this pattern throughout the code. Now we log the
time when an operation began and find the difference in wall clock time
between now and when the event started. This means that sub-millisecond timeouts
now cannot play havoc when trying to determine if something has timed out.
Part of this fix also includes changing the function ast_waitfor() so that it
is possible for it to return less than zero when a negative timeout is given
to it. This makes it actually possible to detect errors in ast_waitfor() when
there is no timeout.
(closes issue ASTERISK-20414)
reported by David M. Lee
Review: https://reviewboard.asterisk.org/r/2135/
........
r375994 | mmichelson | 2012-11-07 11:08:44 -0600 (Wed, 07 Nov 2012) | 3 lines
Remove some debugging that accidentally made it in the last commit.
........
Merged revisions 375993-375994 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 375995 from http://svn.asterisk.org/svn/asterisk/branches/10
........
Merged revisions 376014 from http://svn.asterisk.org/svn/asterisk/branches/11
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@376015 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include/asterisk')
-rw-r--r-- | include/asterisk/channel.h | 4 | ||||
-rw-r--r-- | include/asterisk/time.h | 14 |
2 files changed, 16 insertions, 2 deletions
diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h index ce9ef7aa2..0157d761e 100644 --- a/include/asterisk/channel.h +++ b/include/asterisk/channel.h @@ -1680,7 +1680,7 @@ int ast_is_deferrable_frame(const struct ast_frame *frame); /*! * \brief Wait for a specified amount of time, looking for hangups * \param chan channel to wait for - * \param ms length of time in milliseconds to sleep + * \param ms length of time in milliseconds to sleep. This should never be less than zero. * \details * Waits for a specified amount of time, servicing the channel as required. * \return returns -1 on hangup, otherwise 0. @@ -1690,7 +1690,7 @@ int ast_safe_sleep(struct ast_channel *chan, int ms); /*! * \brief Wait for a specified amount of time, looking for hangups and a condition argument * \param chan channel to wait for - * \param ms length of time in milliseconds to sleep + * \param ms length of time in milliseconds to sleep. * \param cond a function pointer for testing continue condition * \param data argument to be passed to the condition test function * \return returns -1 on hangup, otherwise 0. diff --git a/include/asterisk/time.h b/include/asterisk/time.h index 4fa08723b..dd68db704 100644 --- a/include/asterisk/time.h +++ b/include/asterisk/time.h @@ -152,6 +152,20 @@ struct timeval ast_tvadd(struct timeval a, struct timeval b); struct timeval ast_tvsub(struct timeval a, struct timeval b); /*! + * \brief Calculate remaining milliseconds given a starting timestamp + * and upper bound + * + * If the upper bound is negative, then this indicates that there is no + * upper bound on the amount of time to wait. This will result in a + * negative return. + * + * \param start When timing started being calculated + * \param max_ms The maximum number of milliseconds to wait from start. May be negative. + * \return The number of milliseconds left to wait for. May be negative. + */ +int ast_remaining_ms(struct timeval start, int max_ms); + +/*! * \brief Returns a timeval from sec, usec */ AST_INLINE_API( |