mirror of
https://github.com/pocoproject/poco.git
synced 2025-12-08 12:19:21 +01:00
fix(AsyncNotificationCenter): hang on stop() #5059
This commit is contained in:
committed by
Matej Kenda
parent
7d08a85e5d
commit
1284103b98
@@ -120,6 +120,11 @@ private:
|
||||
|
||||
using Adapter = RunnableAdapter<AsyncNotificationCenter>;
|
||||
|
||||
class ShutdownNotification: public Notification
|
||||
/// Internal notification used to signal the dequeue loop to stop.
|
||||
{
|
||||
};
|
||||
|
||||
const AsyncMode _mode { AsyncMode::ENQUEUE };
|
||||
|
||||
// Async enqueue for notifications
|
||||
|
||||
@@ -180,6 +180,7 @@ void AsyncNotificationCenter::stop()
|
||||
{
|
||||
if (_enqueueThreadStarted.exchange(false))
|
||||
{
|
||||
_nq.enqueueUrgentNotification(new ShutdownNotification);
|
||||
_nq.wakeUpAll();
|
||||
while (!_enqueueThreadDone) Thread::sleep(100);
|
||||
_enqueueThread.join();
|
||||
@@ -207,8 +208,11 @@ void AsyncNotificationCenter::dequeue()
|
||||
Notification::Ptr pNf;
|
||||
_enqueueThreadStarted = true;
|
||||
_enqueueThreadDone = false;
|
||||
while ((pNf = _nq.waitDequeueNotification()))
|
||||
while (true)
|
||||
{
|
||||
pNf = _nq.waitDequeueNotification();
|
||||
if (!pNf) break;
|
||||
if (pNf.cast<ShutdownNotification>()) break;
|
||||
try
|
||||
{
|
||||
notifyObservers(pNf);
|
||||
|
||||
Reference in New Issue
Block a user