Skip to content

Commit d3c8451

Browse files
committed
consume notifications queue in one go, then unlock to let handlers invoke more notifications
1 parent 47b2281 commit d3c8451

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/callbacks.cc

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -456,23 +456,30 @@ void handleNotification(NotifInfo *notif)
456456
void async_cb_handler(uv_async_t *handle)
457457
// ===================================================================
458458
{
459-
NotifInfo *notif;
460-
461-
mutex::scoped_lock sl(zqueue_mutex);
462-
459+
NotifInfo* notif;
460+
std::list<NotifInfo*> notifications;
461+
// consume all the queued notifications
462+
zqueue_mutex.lock();
463463
while (!zqueue.empty()) {
464464
notif = zqueue.front();
465+
notifications.push_back(notif);
466+
zqueue.pop();
467+
}
468+
// unlock the mutex so that notification handlers are safe to invoke more notifications
469+
zqueue_mutex.unlock();
470+
// process notifications
471+
std::list<NotifInfo*>::const_iterator it;
472+
for (it = notifications.begin(); it != notifications.end(); ++it) {
465473
#if OPENZWAVE_SECURITY != 1
466-
if (notif->homeid == 0) {
467-
handleControllerCommand(notif);
474+
if (*it->homeid == 0) {
475+
handleControllerCommand(*it);
468476
} else {
469-
handleNotification(notif);
477+
handleNotification(*it);
470478
}
471479
#else
472-
handleNotification(notif);
480+
handleNotification(*it);
473481
#endif
474-
delete notif;
475-
zqueue.pop();
482+
delete *it;
476483
}
477484
}
478485

0 commit comments

Comments
 (0)