bool Listener::FindNextEventInternal( std::unique_lock<std::mutex> &lock, Broadcaster *broadcaster, // nullptr for any broadcaster const ConstString *broadcaster_names, // nullptr for any event uint32_t num_broadcaster_names, uint32_t event_type_mask, EventSP &event_sp, bool remove) { // NOTE: callers of this function must lock m_events_mutex using a // Mutex::Locker // and pass the locker as the first argument. m_events_mutex is no longer // recursive. Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS)); if (m_events.empty()) return false; Listener::event_collection::iterator pos = m_events.end(); if (broadcaster == nullptr && broadcaster_names == nullptr && event_type_mask == 0) { pos = m_events.begin(); } else { pos = std::find_if(m_events.begin(), m_events.end(), EventMatcher(broadcaster, broadcaster_names, num_broadcaster_names, event_type_mask)); } if (pos != m_events.end()) { event_sp = *pos; if (log != nullptr) log->Printf("%p '%s' Listener::FindNextEventInternal(broadcaster=%p, " "broadcaster_names=%p[%u], event_type_mask=0x%8.8x, " "remove=%i) event %p", static_cast<void *>(this), GetName(), static_cast<void *>(broadcaster), static_cast<const void *>(broadcaster_names), num_broadcaster_names, event_type_mask, remove, static_cast<void *>(event_sp.get())); if (remove) { m_events.erase(pos); // Unlock the event queue here. We've removed this event and are about to // return // it so it should be okay to get the next event off the queue here - and // it might // be useful to do that in the "DoOnRemoval". lock.unlock(); event_sp->DoOnRemoval(); } return true; } event_sp.reset(); return false; }
bool Listener::FindNextEventInternal ( Broadcaster *broadcaster, // NULL for any broadcaster const ConstString *broadcaster_names, // NULL for any event uint32_t num_broadcaster_names, uint32_t event_type_mask, EventSP &event_sp, bool remove) { //LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS)); Mutex::Locker lock(m_events_mutex); if (m_events.empty()) return false; Listener::event_collection::iterator pos = m_events.end(); if (broadcaster == NULL && broadcaster_names == NULL && event_type_mask == 0) { pos = m_events.begin(); } else { pos = std::find_if (m_events.begin(), m_events.end(), EventMatcher (broadcaster, broadcaster_names, num_broadcaster_names, event_type_mask)); } if (pos != m_events.end()) { event_sp = *pos; if (remove) { m_events.erase(pos); if (m_events.empty()) m_cond_wait.SetValue (false, eBroadcastNever); } // Unlock the event queue here. We've removed this event and are about to return // it so it should be okay to get the next event off the queue here - and it might // be useful to do that in the "DoOnRemoval". lock.Unlock(); // Don't call DoOnRemoval if you aren't removing the event... if (remove) event_sp->DoOnRemoval(); return true; } event_sp.reset(); return false; }