I could reproduce the problem by adding sufficient sleep time to the loop. > Magnus Hagander <magnus@hagander.net> wrote: >> I wonder if the else if (sleep > 0) at the bottom of throttle() should just >> be a simple else and always run, resetting last_throttle?
I agree. In fact, I could simplify the code even more.
Since (elapsed + sleep) almost equals to GetCurrentIntegerTimestamp(), we can use the following statement unconditionally (I think I tried too hard to avoid calling GetCurrentIntegerTimestamp too often in the original patch):
throttled_last = GetCurrentIntegerTimestamp();
Thus we can also get rid of the "else" branch that clears both "sleep" and "wait_result".
(The patch contains minor comment refinement that I found useful when seeing the code after years.)