mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-27 11:06:50 +01:00
trunk/branch integration: Timer::skipped()
This commit is contained in:
@@ -46,6 +46,7 @@ namespace Poco {
|
|||||||
Timer::Timer(long startInterval, long periodicInterval):
|
Timer::Timer(long startInterval, long periodicInterval):
|
||||||
_startInterval(startInterval),
|
_startInterval(startInterval),
|
||||||
_periodicInterval(periodicInterval),
|
_periodicInterval(periodicInterval),
|
||||||
|
_skipped(0),
|
||||||
_pCallback(0)
|
_pCallback(0)
|
||||||
{
|
{
|
||||||
poco_assert (startInterval >= 0 && periodicInterval >= 0);
|
poco_assert (startInterval >= 0 && periodicInterval >= 0);
|
||||||
@@ -161,16 +162,31 @@ void Timer::setPeriodicInterval(long milliseconds)
|
|||||||
|
|
||||||
void Timer::run()
|
void Timer::run()
|
||||||
{
|
{
|
||||||
Timestamp now;
|
Poco::Timestamp now;
|
||||||
long interval(0);
|
long interval(0);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
now.update();
|
long sleep(0);
|
||||||
long sleep = static_cast<long>((_nextInvocation - now)/1000);
|
do
|
||||||
if (sleep < 0) sleep = 0;
|
{
|
||||||
|
now.update();
|
||||||
|
sleep = static_cast<long>((_nextInvocation - now)/1000);
|
||||||
|
if (sleep < 0)
|
||||||
|
{
|
||||||
|
if (interval == 0)
|
||||||
|
{
|
||||||
|
sleep = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_nextInvocation += interval*1000;
|
||||||
|
++_skipped;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (sleep < 0);
|
||||||
|
|
||||||
if (_wakeUp.tryWait(sleep))
|
if (_wakeUp.tryWait(sleep))
|
||||||
{
|
{
|
||||||
FastMutex::ScopedLock lock(_mutex);
|
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||||
_nextInvocation.update();
|
_nextInvocation.update();
|
||||||
interval = _periodicInterval;
|
interval = _periodicInterval;
|
||||||
}
|
}
|
||||||
@@ -180,30 +196,34 @@ void Timer::run()
|
|||||||
{
|
{
|
||||||
_pCallback->invoke(*this);
|
_pCallback->invoke(*this);
|
||||||
}
|
}
|
||||||
catch (Exception& exc)
|
catch (Poco::Exception& exc)
|
||||||
{
|
{
|
||||||
ErrorHandler::handle(exc);
|
Poco::ErrorHandler::handle(exc);
|
||||||
}
|
}
|
||||||
catch (std::exception& exc)
|
catch (std::exception& exc)
|
||||||
{
|
{
|
||||||
ErrorHandler::handle(exc);
|
Poco::ErrorHandler::handle(exc);
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
ErrorHandler::handle();
|
Poco::ErrorHandler::handle();
|
||||||
}
|
|
||||||
{
|
|
||||||
FastMutex::ScopedLock lock(_mutex);
|
|
||||||
interval = _periodicInterval;
|
|
||||||
}
|
}
|
||||||
|
interval = _periodicInterval;
|
||||||
}
|
}
|
||||||
_nextInvocation += static_cast<Timestamp::TimeDiff>(interval)*1000;
|
_nextInvocation += interval*1000;
|
||||||
|
_skipped = 0;
|
||||||
}
|
}
|
||||||
while (interval > 0);
|
while (interval > 0);
|
||||||
_done.set();
|
_done.set();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
long Timer::skipped() const
|
||||||
|
{
|
||||||
|
return _skipped;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
AbstractTimerCallback::AbstractTimerCallback()
|
AbstractTimerCallback::AbstractTimerCallback()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user