mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-20 14:02:38 +02:00
fixed GH #2058: Synchronization issue in Poco::Util::Timer at destruction
This commit is contained in:
@@ -83,6 +83,19 @@ public:
|
|||||||
|
|
||||||
bool execute()
|
bool execute()
|
||||||
{
|
{
|
||||||
|
// Check if there's a StopNotification pending.
|
||||||
|
Poco::AutoPtr<TimerNotification> pNf = static_cast<TimerNotification*>(queue().dequeueNotification());
|
||||||
|
while (pNf)
|
||||||
|
{
|
||||||
|
if (pNf.cast<StopNotification>())
|
||||||
|
{
|
||||||
|
queue().clear();
|
||||||
|
_finished.set();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
pNf = static_cast<TimerNotification*>(queue().dequeueNotification());
|
||||||
|
}
|
||||||
|
|
||||||
queue().clear();
|
queue().clear();
|
||||||
_finished.set();
|
_finished.set();
|
||||||
return true;
|
return true;
|
||||||
|
@@ -224,6 +224,42 @@ void TimerTest::testCancel()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TimerTest::testCancelAllStop()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
Timer timer;
|
||||||
|
|
||||||
|
TimerTask::Ptr pTask = new TimerTaskAdapter<TimerTest>(*this, &TimerTest::onTimer);
|
||||||
|
|
||||||
|
timer.scheduleAtFixedRate(pTask, 5000, 5000);
|
||||||
|
|
||||||
|
Poco::Thread::sleep(100);
|
||||||
|
|
||||||
|
timer.cancel(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert (true); // don't hang
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TimerTest::testCancelAllWaitStop()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
Timer timer;
|
||||||
|
|
||||||
|
TimerTask::Ptr pTask = new TimerTaskAdapter<TimerTest>(*this, &TimerTest::onTimer);
|
||||||
|
|
||||||
|
timer.scheduleAtFixedRate(pTask, 5000, 5000);
|
||||||
|
|
||||||
|
Poco::Thread::sleep(100);
|
||||||
|
|
||||||
|
timer.cancel(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert (true); // don't hang
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void TimerTest::setUp()
|
void TimerTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -252,6 +288,8 @@ CppUnit::Test* TimerTest::suite()
|
|||||||
CppUnit_addTest(pSuite, TimerTest, testScheduleIntervalClock);
|
CppUnit_addTest(pSuite, TimerTest, testScheduleIntervalClock);
|
||||||
CppUnit_addTest(pSuite, TimerTest, testScheduleAtFixedRate);
|
CppUnit_addTest(pSuite, TimerTest, testScheduleAtFixedRate);
|
||||||
CppUnit_addTest(pSuite, TimerTest, testCancel);
|
CppUnit_addTest(pSuite, TimerTest, testCancel);
|
||||||
|
CppUnit_addTest(pSuite, TimerTest, testCancelAllStop);
|
||||||
|
CppUnit_addTest(pSuite, TimerTest, testCancelAllWaitStop);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,8 @@ public:
|
|||||||
void testScheduleIntervalTimestamp();
|
void testScheduleIntervalTimestamp();
|
||||||
void testScheduleIntervalClock();
|
void testScheduleIntervalClock();
|
||||||
void testCancel();
|
void testCancel();
|
||||||
|
void testCancelAllStop();
|
||||||
|
void testCancelAllWaitStop();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
Reference in New Issue
Block a user