Skip to content
Permalink
Browse files

Allow RemoveWatcher to be called from a callback called by NotifyWatc…

…hers
  • Loading branch information...
DvdGiessen committed Apr 30, 2018
1 parent c8441b1 commit 7def699f408dede697adf2a54ea5a66c21471eab
Showing with 16 additions and 5 deletions.
  1. +13 −3 cpp/src/Manager.cpp
  2. +3 −2 cpp/src/Manager.h
@@ -3507,7 +3507,14 @@ bool Manager::RemoveWatcher
if( ((*it)->m_callback == _watcher ) && ( (*it)->m_context == _context ) )
{
delete (*it);
m_watchers.erase( it );
list<Watcher*>::iterator next = m_watchers.erase( it );
for( list<list<Watcher*>::iterator*>::iterator extIt = m_watcherIterators.begin(); extIt != m_watcherIterators.end(); ++extIt )
{
if( (**extIt) == it )
{
(**extIt) = next;
}
}
m_notificationMutex->Unlock();
return true;
}
@@ -3528,11 +3535,14 @@ void Manager::NotifyWatchers
)
{
m_notificationMutex->Lock();
for( list<Watcher*>::iterator it = m_watchers.begin(); it != m_watchers.end(); ++it )
list<Watcher*>::iterator it = m_watchers.begin();
m_watcherIterators.push_back(&it);
while( it != m_watchers.end() )
{
Watcher* pWatcher = *it;
Watcher* pWatcher = *(it++);
pWatcher->m_callback( _notification, pWatcher->m_context );
}
m_watcherIterators.pop_back();
m_notificationMutex->Unlock();
}

@@ -1644,9 +1644,10 @@ OPENZWAVE_EXPORT_WARNINGS_ON
};

OPENZWAVE_EXPORT_WARNINGS_OFF
list<Watcher*> m_watchers; // List of all the registered watchers.
list<Watcher*> m_watchers; // List of all the registered watchers.
list<list<Watcher*>::iterator*> m_watcherIterators; // Iterators currently operating on the list of watchers
OPENZWAVE_EXPORT_WARNINGS_ON
Mutex* m_notificationMutex;
Mutex* m_notificationMutex;

//-----------------------------------------------------------------------------
// Controller commands

0 comments on commit 7def699

Please sign in to comment.
You can’t perform that action at this time.