void ListenersBase::remove_void (void* const listener) { ReadWriteMutex::ScopedWriteLockType lock (m_groups_mutex); // Make sure the listener exists #if VF_DEBUG { bool exists = false; for (Groups::iterator iter = m_groups.begin(); iter != m_groups.end();) { Group* group = &(*iter++); // this should never happen while we hold the mutex jassert (!group->empty ()); if (group->contains (listener)) { jassert (!exists); // added twice? exists = true; // keep going to make sure there are no empty groups } } jassert (exists); } #endif // Find the group and remove for (Groups::iterator iter = m_groups.begin(); iter != m_groups.end();) { Group::Ptr group = &(*iter++); // If the listener is in there, take it out. if (group->remove (listener)) { // Are we the last listener? if (group->empty ()) { // Tell proxies to remove the group { ReadWriteMutex::ScopedWriteLockType lock (m_proxies_mutex); for (Proxies::iterator iter = m_proxies.begin (); iter != m_proxies.end ();) { Proxy* proxy = &(*iter++); proxy->remove (group); } } // Remove it from the list and manually release // the reference since the list uses raw pointers. m_groups.erase (m_groups.iterator_to (*group.getObject ())); group->decReferenceCount(); // It is still possible for the group to exist at this // point in a thread queue but it will get processed, // do nothing, and release its own final reference. } break; } } }