未验证 提交 3042bd7a 编写于 作者: J John Salem 提交者: GitHub

Handle early wakeup of counter loop (#57170)

* Fix #56695
* prevent a negative delta value

* PR feedback + bug fix
* bug fix is preexisting: if a user other than the one who is listening sets the interval to 0 while the counter is enabled, it makes the counter continuously submit values. Changed this so that an interval value of <= 0 results in the counter being disabled

* Add assert after offline conversation
上级 afbb7df6
......@@ -127,7 +127,7 @@ private void EnableTimer(float pollingIntervalInSeconds)
Debug.Assert(Monitor.IsEntered(s_counterGroupLock));
if (pollingIntervalInSeconds <= 0)
{
_pollingIntervalInMilliseconds = 0;
DisableTimer();
}
else if (_pollingIntervalInMilliseconds == 0 || pollingIntervalInSeconds * 1000 < _pollingIntervalInMilliseconds)
{
......@@ -187,6 +187,7 @@ private void EnableTimer(float pollingIntervalInSeconds)
private void DisableTimer()
{
Debug.Assert(Monitor.IsEntered(s_counterGroupLock));
_pollingIntervalInMilliseconds = 0;
s_counterGroupEnabledList?.Remove(this);
}
......@@ -252,7 +253,8 @@ private void OnTimer()
{
_timeStampSinceCollectionStarted = now;
TimeSpan delta = now - _nextPollingTimeStamp;
if (delta > TimeSpan.Zero && _pollingIntervalInMilliseconds > 0)
delta = _pollingIntervalInMilliseconds > delta.TotalMilliseconds ? TimeSpan.FromMilliseconds(_pollingIntervalInMilliseconds) : delta;
if (_pollingIntervalInMilliseconds > 0)
_nextPollingTimeStamp += TimeSpan.FromMilliseconds(_pollingIntervalInMilliseconds * Math.Ceiling(delta.TotalMilliseconds / _pollingIntervalInMilliseconds));
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册