From: Rob D. <rk...@rk...> - 2012-12-14 23:17:33
|
On Mon, 2012-12-10 at 00:12 +0000, Rob Day wrote: > The attached patch fixes that behaviour by avoiding a situation where we > divide by zero. The actual patch I'll be committing is below. This fixes a similar bug where if you attempted to make more than 1 call per ms and getmilliseconds() returned 0 (as seemed to happen on Fedora 12 and Centos 5, but which will likely happen 0.1% of the time anywhere) the return code would evaluate to something like (0+1 / 1.1), and casting that to a long would truncate it to 0, meaning no calls would be set up. Best, Rob --- a/opentask.cpp +++ b/opentask.cpp @@ -31,6 +31,7 @@ * Charles P Wright from IBM Research */ #include "sipp.hpp" +#define MAX(a,b) (((a)>(b))?(a):(b)) class opentask *opentask::instance = NULL; unsigned long opentask::calls_since_last_rate_change = 0; @@ -61,7 +62,7 @@ unsigned int opentask::wake() { return 0; } else { /* We need to compute when the next call is going to be opened. */ - return (unsigned long) (last_rate_change_time + ((calls_since_last_rate_change + 1) / (rate/rate_period_ms))); + return (unsigned long) MAX((last_rate_change_time + calls_since_last_rate_change) / (MAX(rate,1)/MAX(rate_period_ms,1))); } } |