Skip to content

Commit b9df0cf

Browse files
authored
Merge pull request #329 from OpenZWave/bugfix/issue#183-disconnect-deadlock
Bugfix/issue#183 disconnect deadlock
2 parents 7c18d8b + 1a1c033 commit b9df0cf

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/callbacks.cc

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -503,12 +503,18 @@ void handleNotification(NotifInfo *notif)
503503
void async_cb_handler(uv_async_t *handle)
504504
// ===================================================================
505505
{
506-
NotifInfo *notif;
507-
508-
mutex::scoped_lock sl(zqueue_mutex);
509-
510-
while (!zqueue.empty()) {
511-
notif = zqueue.front();
506+
NotifInfo* notif;
507+
std::queue<NotifInfo*> notifications;
508+
// consume all the queued notifications
509+
{
510+
mutex::scoped_lock sl(zqueue_mutex);
511+
// http://media2.giphy.com/media/MS0fQBmGGMaRy/giphy.gif
512+
swap(notifications, zqueue);
513+
}
514+
// process notifications
515+
while (!notifications.empty()) {
516+
notif = notifications.front();
517+
notifications.pop();
512518
#if OPENZWAVE_SECURITY != 1
513519
if (notif->homeid == 0) {
514520
handleControllerCommand(notif);
@@ -518,8 +524,6 @@ void async_cb_handler(uv_async_t *handle)
518524
#else
519525
handleNotification(notif);
520526
#endif
521-
delete notif;
522-
zqueue.pop();
523527
}
524528
}
525529

0 commit comments

Comments
 (0)