From d35031e1e5b1dbe31f960a1054f139f7ba2c3f35 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Wed, 30 Nov 2016 10:41:42 +0000 Subject: [PATCH] Use Timeout<> in the Listener class Summary: Communication classes use the Timeout<> class to specify the timeout. Listener class was converted to chrono some time ago, but it used a different meaning for a timeout of zero (Listener: infinite wait, Communication: no wait). Instead, Listener provided separate functions which performed a non-blocking event read. This converts the Listener class to the new Timeout class, to improve consistency. It also allows us to get merge the different GetNextEvent*** and WaitForEvent*** functions into one. No functional change intended. Reviewers: jingham, clayborg, zturner Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D27136 llvm-svn: 288238 --- lldb/include/lldb/Core/Listener.h | 36 +++-------- lldb/source/API/SBDebugger.cpp | 4 +- lldb/source/API/SBListener.cpp | 26 ++++---- lldb/source/Core/Communication.cpp | 8 +-- lldb/source/Core/Debugger.cpp | 4 +- lldb/source/Core/IOHandler.cpp | 2 +- lldb/source/Core/Listener.cpp | 71 +++++++--------------- .../Process/gdb-remote/ProcessGDBRemote.cpp | 6 +- lldb/source/Target/Process.cpp | 46 +++++++++----- lldb/unittests/Core/BroadcasterTest.cpp | 11 ++-- lldb/unittests/Core/ListenerTest.cpp | 66 ++++++++++---------- .../Process/gdb-remote/GDBRemoteClientBaseTest.cpp | 5 +- 12 files changed, 125 insertions(+), 160 deletions(-) diff --git a/lldb/include/lldb/Core/Listener.h b/lldb/include/lldb/Core/Listener.h index 66ddfc3..b82844e 100644 --- a/lldb/include/lldb/Core/Listener.h +++ b/lldb/include/lldb/Core/Listener.h @@ -22,6 +22,7 @@ // Other libraries and framework includes // Project includes #include "lldb/Core/Event.h" +#include "lldb/Utility/Timeout.h" #include "lldb/lldb-private.h" namespace lldb_private { @@ -70,18 +71,6 @@ public: bool StopListeningForEvents(Broadcaster *broadcaster, uint32_t event_mask); - // Returns true if an event was received, false if we timed out. - bool WaitForEvent(const std::chrono::microseconds &timeout, - lldb::EventSP &event_sp); - - bool WaitForEventForBroadcaster(const std::chrono::microseconds &timeout, - Broadcaster *broadcaster, - lldb::EventSP &event_sp); - - bool WaitForEventForBroadcasterWithType( - const std::chrono::microseconds &timeout, Broadcaster *broadcaster, - uint32_t event_type_mask, lldb::EventSP &event_sp); - Event *PeekAtNextEvent(); Event *PeekAtNextEventForBroadcaster(Broadcaster *broadcaster); @@ -89,14 +78,16 @@ public: Event *PeekAtNextEventForBroadcasterWithType(Broadcaster *broadcaster, uint32_t event_type_mask); - bool GetNextEvent(lldb::EventSP &event_sp); + // Returns true if an event was received, false if we timed out. + bool GetEvent(lldb::EventSP &event_sp, const Timeout &timeout); - bool GetNextEventForBroadcaster(Broadcaster *broadcaster, - lldb::EventSP &event_sp); + bool GetEventForBroadcaster(Broadcaster *broadcaster, lldb::EventSP &event_sp, + const Timeout &timeout); - bool GetNextEventForBroadcasterWithType(Broadcaster *broadcaster, - uint32_t event_type_mask, - lldb::EventSP &event_sp); + bool GetEventForBroadcasterWithType(Broadcaster *broadcaster, + uint32_t event_type_mask, + lldb::EventSP &event_sp, + const Timeout &timeout); size_t HandleBroadcastEvent(lldb::EventSP &event_sp); @@ -128,14 +119,7 @@ private: uint32_t num_sources, uint32_t event_type_mask, lldb::EventSP &event_sp, bool remove); - bool - GetNextEventInternal(Broadcaster *broadcaster, // nullptr for any broadcaster - const ConstString *sources, // nullptr for any event - uint32_t num_sources, uint32_t event_type_mask, - lldb::EventSP &event_sp); - - bool - WaitForEventsInternal(const std::chrono::microseconds &timeout, + bool GetEventInternal(const Timeout &timeout, Broadcaster *broadcaster, // nullptr for any broadcaster const ConstString *sources, // nullptr for any event uint32_t num_sources, uint32_t event_type_mask, diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp index c74bc75..97e6f7b 100644 --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -368,8 +368,8 @@ void SBDebugger::HandleCommand(const char *command) { if (process_sp) { EventSP event_sp; ListenerSP lldb_listener_sp = m_opaque_sp->GetListener(); - while (lldb_listener_sp->GetNextEventForBroadcaster(process_sp.get(), - event_sp)) { + while (lldb_listener_sp->GetEventForBroadcaster( + process_sp.get(), event_sp, std::chrono::seconds(0))) { SBEvent event(event_sp); HandleProcessEvent(process, event, GetOutputFileHandle(), GetErrorFileHandle()); diff --git a/lldb/source/API/SBListener.cpp b/lldb/source/API/SBListener.cpp index cbbfd8e..501535a 100644 --- a/lldb/source/API/SBListener.cpp +++ b/lldb/source/API/SBListener.cpp @@ -156,14 +156,14 @@ bool SBListener::WaitForEvent(uint32_t timeout_secs, SBEvent &event) { bool success = false; if (m_opaque_sp) { - std::chrono::microseconds timeout = std::chrono::microseconds(0); + Timeout timeout(llvm::None); if (timeout_secs != UINT32_MAX) { assert(timeout_secs != 0); // Take this out after all calls with timeout // set to zero have been removed.... timeout = std::chrono::seconds(timeout_secs); } EventSP event_sp; - if (m_opaque_sp->WaitForEvent(timeout, event_sp)) { + if (m_opaque_sp->GetEvent(event_sp, timeout)) { event.reset(event_sp); success = true; } @@ -191,12 +191,12 @@ bool SBListener::WaitForEventForBroadcaster(uint32_t num_seconds, const SBBroadcaster &broadcaster, SBEvent &event) { if (m_opaque_sp && broadcaster.IsValid()) { - std::chrono::microseconds timeout = std::chrono::microseconds(0); + Timeout timeout(llvm::None); if (num_seconds != UINT32_MAX) timeout = std::chrono::seconds(num_seconds); EventSP event_sp; - if (m_opaque_sp->WaitForEventForBroadcaster(timeout, broadcaster.get(), - event_sp)) { + if (m_opaque_sp->GetEventForBroadcaster(broadcaster.get(), event_sp, + timeout)) { event.reset(event_sp); return true; } @@ -209,12 +209,12 @@ bool SBListener::WaitForEventForBroadcasterWithType( uint32_t num_seconds, const SBBroadcaster &broadcaster, uint32_t event_type_mask, SBEvent &event) { if (m_opaque_sp && broadcaster.IsValid()) { - std::chrono::microseconds timeout = std::chrono::microseconds(0); + Timeout timeout(llvm::None); if (num_seconds != UINT32_MAX) timeout = std::chrono::seconds(num_seconds); EventSP event_sp; - if (m_opaque_sp->WaitForEventForBroadcasterWithType( - timeout, broadcaster.get(), event_type_mask, event_sp)) { + if (m_opaque_sp->GetEventForBroadcasterWithType( + broadcaster.get(), event_type_mask, event_sp, timeout)) { event.reset(event_sp); return true; } @@ -257,7 +257,7 @@ bool SBListener::PeekAtNextEventForBroadcasterWithType( bool SBListener::GetNextEvent(SBEvent &event) { if (m_opaque_sp) { EventSP event_sp; - if (m_opaque_sp->GetNextEvent(event_sp)) { + if (m_opaque_sp->GetEvent(event_sp, std::chrono::seconds(0))) { event.reset(event_sp); return true; } @@ -270,7 +270,8 @@ bool SBListener::GetNextEventForBroadcaster(const SBBroadcaster &broadcaster, SBEvent &event) { if (m_opaque_sp && broadcaster.IsValid()) { EventSP event_sp; - if (m_opaque_sp->GetNextEventForBroadcaster(broadcaster.get(), event_sp)) { + if (m_opaque_sp->GetEventForBroadcaster(broadcaster.get(), event_sp, + std::chrono::seconds(0))) { event.reset(event_sp); return true; } @@ -284,8 +285,9 @@ bool SBListener::GetNextEventForBroadcasterWithType( SBEvent &event) { if (m_opaque_sp && broadcaster.IsValid()) { EventSP event_sp; - if (m_opaque_sp->GetNextEventForBroadcasterWithType( - broadcaster.get(), event_type_mask, event_sp)) { + if (m_opaque_sp->GetEventForBroadcasterWithType(broadcaster.get(), + event_type_mask, event_sp, + std::chrono::seconds(0))) { event.reset(event_sp); return true; } diff --git a/lldb/source/Core/Communication.cpp b/lldb/source/Core/Communication.cpp index 113a847..3d3abea 100644 --- a/lldb/source/Core/Communication.cpp +++ b/lldb/source/Core/Communication.cpp @@ -115,8 +115,6 @@ bool Communication::HasConnection() const { size_t Communication::Read(void *dst, size_t dst_len, const Timeout &timeout, ConnectionStatus &status, Error *error_ptr) { - using std::chrono::microseconds; - lldb_private::LogIfAnyCategoriesSet( LIBLLDB_LOG_COMMUNICATION, "%p Communication::Read (dst = %p, dst_len = %" PRIu64 @@ -143,9 +141,7 @@ size_t Communication::Read(void *dst, size_t dst_len, listener_sp->StartListeningForEvents( this, eBroadcastBitReadThreadGotBytes | eBroadcastBitReadThreadDidExit); EventSP event_sp; - microseconds listener_timeout = - timeout ? microseconds(*timeout) : microseconds(0); - while (listener_sp->WaitForEvent(listener_timeout, event_sp)) { + while (listener_sp->GetEvent(event_sp, timeout)) { const uint32_t event_type = event_sp->GetType(); if (event_type & eBroadcastBitReadThreadGotBytes) { return GetCachedBytes(dst, dst_len); @@ -386,7 +382,7 @@ void Communication::SynchronizeWithReadThread() { // Wait for the synchronization event. EventSP event_sp; - listener_sp->WaitForEvent(std::chrono::microseconds(0), event_sp); + listener_sp->GetEvent(event_sp, llvm::None); } void Communication::SetConnection(Connection *connection) { diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index e66fb23..8f888a5 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -1535,7 +1535,7 @@ void Debugger::DefaultEventHandler() { bool done = false; while (!done) { EventSP event_sp; - if (listener_sp->WaitForEvent(std::chrono::microseconds(0), event_sp)) { + if (listener_sp->GetEvent(event_sp, llvm::None)) { if (event_sp) { Broadcaster *broadcaster = event_sp->GetBroadcaster(); if (broadcaster) { @@ -1616,7 +1616,7 @@ bool Debugger::StartEventHandlerThread() { // to wait an infinite amount of time for it (nullptr timeout as the first // parameter) lldb::EventSP event_sp; - listener_sp->WaitForEvent(std::chrono::microseconds(0), event_sp); + listener_sp->GetEvent(event_sp, llvm::None); } return m_event_handler_thread.IsJoinable(); } diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp index e123fdb..ed85c59 100644 --- a/lldb/source/Core/IOHandler.cpp +++ b/lldb/source/Core/IOHandler.cpp @@ -1847,7 +1847,7 @@ public: // Just a timeout from using halfdelay(), check for events EventSP event_sp; while (listener_sp->PeekAtNextEvent()) { - listener_sp->GetNextEvent(event_sp); + listener_sp->GetEvent(event_sp, std::chrono::seconds(0)); if (event_sp) { Broadcaster *broadcaster = event_sp->GetBroadcaster(); diff --git a/lldb/source/Core/Listener.cpp b/lldb/source/Core/Listener.cpp index 216a302..3adb677 100644 --- a/lldb/source/Core/Listener.cpp +++ b/lldb/source/Core/Listener.cpp @@ -345,44 +345,17 @@ Listener::PeekAtNextEventForBroadcasterWithType(Broadcaster *broadcaster, return nullptr; } -bool Listener::GetNextEventInternal( - 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) { - std::unique_lock guard(m_events_mutex); - return FindNextEventInternal(guard, broadcaster, broadcaster_names, - num_broadcaster_names, event_type_mask, event_sp, - true); -} - -bool Listener::GetNextEvent(EventSP &event_sp) { - return GetNextEventInternal(nullptr, nullptr, 0, 0, event_sp); -} - -bool Listener::GetNextEventForBroadcaster(Broadcaster *broadcaster, - EventSP &event_sp) { - return GetNextEventInternal(broadcaster, nullptr, 0, 0, event_sp); -} - -bool Listener::GetNextEventForBroadcasterWithType(Broadcaster *broadcaster, - uint32_t event_type_mask, - EventSP &event_sp) { - return GetNextEventInternal(broadcaster, nullptr, 0, event_type_mask, - event_sp); -} - -bool Listener::WaitForEventsInternal( - const std::chrono::microseconds &timeout, +bool Listener::GetEventInternal( + const Timeout &timeout, 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) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS)); if (log != nullptr) - log->Printf("%p Listener::WaitForEventsInternal (timeout = %llu us) for %s", - static_cast(this), - static_cast(timeout.count()), + log->Printf("%p Listener::GetEventInternal (timeout = %llu us) for %s", + static_cast(this), static_cast( + timeout ? timeout->count() : -1), m_name.c_str()); std::unique_lock lock(m_events_mutex); @@ -394,23 +367,22 @@ bool Listener::WaitForEventsInternal( return true; } else { std::cv_status result = std::cv_status::no_timeout; - if (timeout == std::chrono::microseconds(0)) + if (!timeout) m_events_condition.wait(lock); else - result = m_events_condition.wait_for(lock, timeout); + result = m_events_condition.wait_for(lock, *timeout); if (result == std::cv_status::timeout) { log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS); if (log) - log->Printf("%p Listener::WaitForEventsInternal() timed out for %s", + log->Printf("%p Listener::GetEventInternal() timed out for %s", static_cast(this), m_name.c_str()); return false; } else if (result != std::cv_status::no_timeout) { log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS); if (log) - log->Printf( - "%p Listener::WaitForEventsInternal() unknown error for %s", - static_cast(this), m_name.c_str()); + log->Printf("%p Listener::GetEventInternal() unknown error for %s", + static_cast(this), m_name.c_str()); return false; } } @@ -419,22 +391,21 @@ bool Listener::WaitForEventsInternal( return false; } -bool Listener::WaitForEventForBroadcasterWithType( - const std::chrono::microseconds &timeout, Broadcaster *broadcaster, - uint32_t event_type_mask, EventSP &event_sp) { - return WaitForEventsInternal(timeout, broadcaster, nullptr, 0, - event_type_mask, event_sp); +bool Listener::GetEventForBroadcasterWithType( + Broadcaster *broadcaster, uint32_t event_type_mask, EventSP &event_sp, + const Timeout &timeout) { + return GetEventInternal(timeout, broadcaster, nullptr, 0, event_type_mask, + event_sp); } -bool Listener::WaitForEventForBroadcaster( - const std::chrono::microseconds &timeout, Broadcaster *broadcaster, - EventSP &event_sp) { - return WaitForEventsInternal(timeout, broadcaster, nullptr, 0, 0, event_sp); +bool Listener::GetEventForBroadcaster(Broadcaster *broadcaster, + EventSP &event_sp, + const Timeout &timeout) { + return GetEventInternal(timeout, broadcaster, nullptr, 0, 0, event_sp); } -bool Listener::WaitForEvent(const std::chrono::microseconds &timeout, - EventSP &event_sp) { - return WaitForEventsInternal(timeout, nullptr, nullptr, 0, 0, event_sp); +bool Listener::GetEvent(EventSP &event_sp, const Timeout &timeout) { + return GetEventInternal(timeout, nullptr, nullptr, 0, 0, event_sp); } size_t Listener::HandleBroadcastEvent(EventSP &event_sp) { diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 876af4f..fac5290 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -1459,8 +1459,7 @@ Error ProcessGDBRemote::DoResume() { new EventDataBytes(continue_packet.GetString().data(), continue_packet.GetSize())); - if (listener_sp->WaitForEvent(std::chrono::seconds(5), event_sp) == - false) { + if (listener_sp->GetEvent(event_sp, std::chrono::seconds(5)) == false) { error.SetErrorString("Resume timed out."); if (log) log->Printf("ProcessGDBRemote::DoResume: Resume timed out."); @@ -3534,8 +3533,7 @@ thread_result_t ProcessGDBRemote::AsyncThread(void *arg) { log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") listener.WaitForEvent (NULL, event_sp)...", __FUNCTION__, arg, process->GetID()); - if (process->m_async_listener_sp->WaitForEvent(std::chrono::microseconds(0), - event_sp)) { + if (process->m_async_listener_sp->GetEvent(event_sp, llvm::None)) { const uint32_t event_type = event_sp->GetType(); if (event_sp->BroadcasterIs(&process->m_async_broadcaster)) { if (log) diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index f5a5d47..ad0c134 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -68,6 +68,15 @@ using namespace lldb; using namespace lldb_private; +// A temporary function to convert between old representations of timeouts (0 +// means infinite wait) and new Timeout class (0 means "poll"). +// TODO(labath): Fix up all callers and remove this. +static Timeout ConvertTimeout(std::chrono::microseconds t) { + if (t == std::chrono::microseconds(0)) + return llvm::None; + return t; +} + // Comment out line below to disable memory caching, overriding the process // setting // target.process.disable-memory-cache @@ -937,7 +946,9 @@ void Process::SynchronouslyNotifyStateChanged(StateType state) { StateType Process::GetNextEvent(EventSP &event_sp) { StateType state = eStateInvalid; - if (m_listener_sp->GetNextEventForBroadcaster(this, event_sp) && event_sp) + if (m_listener_sp->GetEventForBroadcaster(this, event_sp, + std::chrono::seconds(0)) && + event_sp) state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); return state; @@ -1289,9 +1300,9 @@ Process::WaitForStateChangedEvents(const std::chrono::microseconds &timeout, listener_sp = m_listener_sp; StateType state = eStateInvalid; - if (listener_sp->WaitForEventForBroadcasterWithType( - timeout, this, eBroadcastBitStateChanged | eBroadcastBitInterrupt, - event_sp)) { + if (listener_sp->GetEventForBroadcasterWithType( + this, eBroadcastBitStateChanged | eBroadcastBitInterrupt, event_sp, + ConvertTimeout(timeout))) { if (event_sp && event_sp->GetType() == eBroadcastBitStateChanged) state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); else if (log) @@ -1335,9 +1346,10 @@ StateType Process::WaitForStateChangedEventsPrivate( static_cast(timeout.count())); StateType state = eStateInvalid; - if (m_private_state_listener_sp->WaitForEventForBroadcasterWithType( - timeout, &m_private_state_broadcaster, - eBroadcastBitStateChanged | eBroadcastBitInterrupt, event_sp)) + if (m_private_state_listener_sp->GetEventForBroadcasterWithType( + &m_private_state_broadcaster, + eBroadcastBitStateChanged | eBroadcastBitInterrupt, event_sp, + ConvertTimeout(timeout))) if (event_sp && event_sp->GetType() == eBroadcastBitStateChanged) state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); @@ -1360,10 +1372,12 @@ bool Process::WaitForEventsPrivate(const std::chrono::microseconds &timeout, static_cast(timeout.count())); if (control_only) - return m_private_state_listener_sp->WaitForEventForBroadcaster( - timeout, &m_private_state_control_broadcaster, event_sp); + return m_private_state_listener_sp->GetEventForBroadcaster( + &m_private_state_control_broadcaster, event_sp, + ConvertTimeout(timeout)); else - return m_private_state_listener_sp->WaitForEvent(timeout, event_sp); + return m_private_state_listener_sp->GetEvent(event_sp, + ConvertTimeout(timeout)); } bool Process::IsRunning() const { @@ -2881,7 +2895,7 @@ Error Process::LoadCore() { // Wait indefinitely for a stopped event since we just posted one above... lldb::EventSP event_sp; - listener_sp->WaitForEvent(std::chrono::microseconds(0), event_sp); + listener_sp->GetEvent(event_sp, llvm::None); StateType state = ProcessEventData::GetStateFromEvent(event_sp.get()); if (!StateIsStoppedState(state, false)) { @@ -5116,8 +5130,8 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx, } } - got_event = listener_sp->WaitForEvent(std::chrono::microseconds(500000), - event_sp); + got_event = + listener_sp->GetEvent(event_sp, std::chrono::milliseconds(500)); if (!got_event) { if (log) log->Printf("Process::RunThreadPlan(): didn't get any event after " @@ -5226,7 +5240,7 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx, got_event = false; } else #endif - got_event = listener_sp->WaitForEvent(timeout, event_sp); + got_event = listener_sp->GetEvent(event_sp, ConvertTimeout(timeout)); if (got_event) { if (event_sp) { @@ -5426,8 +5440,8 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx, if (log) log->PutCString("Process::RunThreadPlan(): Halt succeeded."); - got_event = listener_sp->WaitForEvent( - std::chrono::microseconds(500000), event_sp); + got_event = + listener_sp->GetEvent(event_sp, std::chrono::milliseconds(500)); if (got_event) { stop_state = diff --git a/lldb/unittests/Core/BroadcasterTest.cpp b/lldb/unittests/Core/BroadcasterTest.cpp index cc6f241..e379582 100644 --- a/lldb/unittests/Core/BroadcasterTest.cpp +++ b/lldb/unittests/Core/BroadcasterTest.cpp @@ -21,6 +21,7 @@ using namespace lldb_private; TEST(BroadcasterTest, BroadcastEvent) { EventSP event_sp; Broadcaster broadcaster(nullptr, "test-broadcaster"); + std::chrono::seconds timeout(0); // Create a listener, sign it up, make sure it recieves an event. ListenerSP listener1_sp = Listener::MakeListener("test-listener1"); @@ -28,7 +29,7 @@ TEST(BroadcasterTest, BroadcastEvent) { EXPECT_EQ(event_mask1, listener1_sp->StartListeningForEvents(&broadcaster, event_mask1)); broadcaster.BroadcastEvent(event_mask1, nullptr); - EXPECT_TRUE(listener1_sp->GetNextEvent(event_sp)); + EXPECT_TRUE(listener1_sp->GetEvent(event_sp, timeout)); EXPECT_EQ(event_mask1, event_sp->GetType()); { @@ -38,20 +39,20 @@ TEST(BroadcasterTest, BroadcastEvent) { EXPECT_EQ(event_mask2, listener2_sp->StartListeningForEvents( &broadcaster, event_mask1 | event_mask2)); broadcaster.BroadcastEvent(event_mask2, nullptr); - EXPECT_TRUE(listener2_sp->GetNextEvent(event_sp)); + EXPECT_TRUE(listener2_sp->GetEvent(event_sp, timeout)); EXPECT_EQ(event_mask2, event_sp->GetType()); // Both listeners should get this event. broadcaster.BroadcastEvent(event_mask1, nullptr); - EXPECT_TRUE(listener1_sp->GetNextEvent(event_sp)); + EXPECT_TRUE(listener1_sp->GetEvent(event_sp, timeout)); EXPECT_EQ(event_mask1, event_sp->GetType()); - EXPECT_TRUE(listener2_sp->GetNextEvent(event_sp)); + EXPECT_TRUE(listener2_sp->GetEvent(event_sp, timeout)); EXPECT_EQ(event_mask2, event_sp->GetType()); } // Now again only one listener should be active. broadcaster.BroadcastEvent(event_mask1, nullptr); - EXPECT_TRUE(listener1_sp->GetNextEvent(event_sp)); + EXPECT_TRUE(listener1_sp->GetEvent(event_sp, timeout)); EXPECT_EQ(event_mask1, event_sp->GetType()); } diff --git a/lldb/unittests/Core/ListenerTest.cpp b/lldb/unittests/Core/ListenerTest.cpp index 807b747..7c5a52e 100644 --- a/lldb/unittests/Core/ListenerTest.cpp +++ b/lldb/unittests/Core/ListenerTest.cpp @@ -17,7 +17,7 @@ using namespace lldb; using namespace lldb_private; -TEST(ListenerTest, GetNextEvent) { +TEST(ListenerTest, GetEventImmediate) { EventSP event_sp; Broadcaster broadcaster(nullptr, "test-broadcaster"); @@ -27,31 +27,34 @@ TEST(ListenerTest, GetNextEvent) { ASSERT_EQ(event_mask, listener_sp->StartListeningForEvents(&broadcaster, event_mask)); + const std::chrono::seconds timeout(0); // Without any events sent, these should return false. - EXPECT_FALSE(listener_sp->GetNextEvent(event_sp)); - EXPECT_FALSE(listener_sp->GetNextEventForBroadcaster(nullptr, event_sp)); - EXPECT_FALSE(listener_sp->GetNextEventForBroadcaster(&broadcaster, event_sp)); - EXPECT_FALSE(listener_sp->GetNextEventForBroadcasterWithType( - &broadcaster, event_mask, event_sp)); + EXPECT_FALSE(listener_sp->GetEvent(event_sp, timeout)); + EXPECT_FALSE(listener_sp->GetEventForBroadcaster(nullptr, event_sp, timeout)); + EXPECT_FALSE( + listener_sp->GetEventForBroadcaster(&broadcaster, event_sp, timeout)); + EXPECT_FALSE(listener_sp->GetEventForBroadcasterWithType( + &broadcaster, event_mask, event_sp, timeout)); // Now send events and make sure they get it. broadcaster.BroadcastEvent(event_mask, nullptr); - EXPECT_TRUE(listener_sp->GetNextEvent(event_sp)); + EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout)); broadcaster.BroadcastEvent(event_mask, nullptr); - EXPECT_TRUE(listener_sp->GetNextEventForBroadcaster(nullptr, event_sp)); + EXPECT_TRUE(listener_sp->GetEventForBroadcaster(nullptr, event_sp, timeout)); broadcaster.BroadcastEvent(event_mask, nullptr); - EXPECT_TRUE(listener_sp->GetNextEventForBroadcaster(&broadcaster, event_sp)); + EXPECT_TRUE( + listener_sp->GetEventForBroadcaster(&broadcaster, event_sp, timeout)); broadcaster.BroadcastEvent(event_mask, nullptr); - EXPECT_FALSE(listener_sp->GetNextEventForBroadcasterWithType( - &broadcaster, event_mask * 2, event_sp)); - EXPECT_TRUE(listener_sp->GetNextEventForBroadcasterWithType( - &broadcaster, event_mask, event_sp)); + EXPECT_FALSE(listener_sp->GetEventForBroadcasterWithType( + &broadcaster, event_mask * 2, event_sp, timeout)); + EXPECT_TRUE(listener_sp->GetEventForBroadcasterWithType( + &broadcaster, event_mask, event_sp, timeout)); } -TEST(ListenerTest, WaitForEvent) { +TEST(ListenerTest, GetEventWait) { EventSP event_sp; Broadcaster broadcaster(nullptr, "test-broadcaster"); @@ -63,33 +66,30 @@ TEST(ListenerTest, WaitForEvent) { // Without any events sent, these should make a short wait and return false. std::chrono::microseconds timeout(10); - EXPECT_FALSE(listener_sp->WaitForEvent(timeout, event_sp)); + EXPECT_FALSE(listener_sp->GetEvent(event_sp, timeout)); + EXPECT_FALSE(listener_sp->GetEventForBroadcaster(nullptr, event_sp, timeout)); EXPECT_FALSE( - listener_sp->WaitForEventForBroadcaster(timeout, nullptr, event_sp)); - EXPECT_FALSE( - listener_sp->WaitForEventForBroadcaster(timeout, &broadcaster, event_sp)); - EXPECT_FALSE(listener_sp->WaitForEventForBroadcasterWithType( - timeout, &broadcaster, event_mask, event_sp)); + listener_sp->GetEventForBroadcaster(&broadcaster, event_sp, timeout)); + EXPECT_FALSE(listener_sp->GetEventForBroadcasterWithType( + &broadcaster, event_mask, event_sp, timeout)); // Now send events and make sure they get it. broadcaster.BroadcastEvent(event_mask, nullptr); - EXPECT_TRUE(listener_sp->WaitForEvent(timeout, event_sp)); + EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout)); broadcaster.BroadcastEvent(event_mask, nullptr); - EXPECT_TRUE( - listener_sp->WaitForEventForBroadcaster(timeout, nullptr, event_sp)); + EXPECT_TRUE(listener_sp->GetEventForBroadcaster(nullptr, event_sp, timeout)); broadcaster.BroadcastEvent(event_mask, nullptr); EXPECT_TRUE( - listener_sp->WaitForEventForBroadcaster(timeout, &broadcaster, event_sp)); + listener_sp->GetEventForBroadcaster(&broadcaster, event_sp, timeout)); broadcaster.BroadcastEvent(event_mask, nullptr); - EXPECT_FALSE(listener_sp->WaitForEventForBroadcasterWithType( - timeout, &broadcaster, event_mask * 2, event_sp)); - EXPECT_TRUE(listener_sp->WaitForEventForBroadcasterWithType( - timeout, &broadcaster, event_mask, event_sp)); + EXPECT_FALSE(listener_sp->GetEventForBroadcasterWithType( + &broadcaster, event_mask * 2, event_sp, timeout)); + EXPECT_TRUE(listener_sp->GetEventForBroadcasterWithType( + &broadcaster, event_mask, event_sp, timeout)); - timeout = std::chrono::seconds(0); auto delayed_broadcast = [&] { std::this_thread::sleep_for(std::chrono::milliseconds(10)); broadcaster.BroadcastEvent(event_mask, nullptr); @@ -99,16 +99,16 @@ TEST(ListenerTest, WaitForEvent) { // broadcast sends. std::future async_broadcast = std::async(std::launch::async, delayed_broadcast); - EXPECT_TRUE(listener_sp->WaitForEvent(timeout, event_sp)); + EXPECT_TRUE(listener_sp->GetEvent(event_sp, llvm::None)); async_broadcast.get(); async_broadcast = std::async(std::launch::async, delayed_broadcast); EXPECT_TRUE( - listener_sp->WaitForEventForBroadcaster(timeout, &broadcaster, event_sp)); + listener_sp->GetEventForBroadcaster(&broadcaster, event_sp, llvm::None)); async_broadcast.get(); async_broadcast = std::async(std::launch::async, delayed_broadcast); - EXPECT_TRUE(listener_sp->WaitForEventForBroadcasterWithType( - timeout, &broadcaster, event_mask, event_sp)); + EXPECT_TRUE(listener_sp->GetEventForBroadcasterWithType( + &broadcaster, event_mask, event_sp, llvm::None)); async_broadcast.get(); } diff --git a/lldb/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp b/lldb/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp index 1c88b3f..2cfd52f 100644 --- a/lldb/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp +++ b/lldb/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp @@ -67,9 +67,8 @@ struct ContinueFixture { void WaitForRunEvent() { EventSP event_sp; - listener_sp->WaitForEventForBroadcasterWithType( - std::chrono::microseconds(0), &client, - TestClient::eBroadcastBitRunPacketSent, event_sp); + listener_sp->GetEventForBroadcasterWithType( + &client, TestClient::eBroadcastBitRunPacketSent, event_sp, llvm::None); } }; -- 2.7.4