diff options
Diffstat (limited to 'lldb/source/Plugins/Process/Linux/ThreadStateCoordinator.h')
| -rw-r--r-- | lldb/source/Plugins/Process/Linux/ThreadStateCoordinator.h | 63 |
1 files changed, 51 insertions, 12 deletions
diff --git a/lldb/source/Plugins/Process/Linux/ThreadStateCoordinator.h b/lldb/source/Plugins/Process/Linux/ThreadStateCoordinator.h index a275ce651a3..be1b70a33ea 100644 --- a/lldb/source/Plugins/Process/Linux/ThreadStateCoordinator.h +++ b/lldb/source/Plugins/Process/Linux/ThreadStateCoordinator.h @@ -10,7 +10,11 @@ #ifndef lldb_ThreadStateCoordinator_h #define lldb_ThreadStateCoordinator_h +#include <condition_variable> #include <functional> +#include <mutex> +#include <queue> +#include <unordered_map> #include <unordered_set> #include "lldb/lldb-types.h" @@ -24,6 +28,9 @@ namespace lldb_private // Typedefs. typedef std::unordered_set<lldb::tid_t> ThreadIDSet; + // Protocols. + + // Callback definitions. typedef std::function<void (lldb::tid_t tid)> ThreadIDFunc; typedef std::function<void (const char *format, va_list args)> LogFunc; @@ -34,7 +41,7 @@ namespace lldb_private // The main purpose of the class: triggering an action after // a given set of threads stop. void - CallAfterThreadsStop (const lldb::tid_t triggering_tid, + CallAfterThreadsStop (lldb::tid_t triggering_tid, const ThreadIDSet &wait_for_stop_tids, const ThreadIDFunc &request_thread_stop_func, const ThreadIDFunc &call_after_func); @@ -59,26 +66,58 @@ namespace lldb_private // Process the next event, returning false when the coordinator is all done. // This call is synchronous and blocks when there are no events pending. // Expected usage is to run this in a separate thread until the function - // returns false. + // returns false. Always call this from the same thread. The processing + // logic assumes the execution of this is implicitly serialized. bool ProcessNextEvent (); private: - enum EventType - { - eInvalid, - eEventTypeCallAfterThreadsStop, - eEventTypeThreadStopped, - eEventTypeThreadResumed, - eEventTypeThreadCreated, - eEventTypeThreadDied, - }; + // Typedefs. + class EventBase; + + class EventCallAfterThreadsStop; + class EventStopCoordinator; + class EventThreadStopped; + + typedef std::shared_ptr<EventBase> EventBaseSP; + + typedef std::queue<EventBaseSP> QueueType; + + typedef std::unordered_map<lldb::tid_t, bool> TIDBoolMap; + + + // Private member functions. + void + EnqueueEvent (EventBaseSP event_sp); + + EventBaseSP + DequeueEventWithWait (); - bool m_done_b; + void + SetPendingNotification (const EventBaseSP &event_sp); + + void + ThreadDidStop (lldb::tid_t tid); + void + Log (const char *format, ...); + + // Member variables. LogFunc m_log_func; + QueueType m_event_queue; + // For now we do simple read/write lock strategy with efficient wait-for-data. + // We can replace with entirely non-blocking queue later but we still want the + // reader to sleep when nothing is available - this will be a bursty but infrequent + // event mechanism. + std::condition_variable m_queue_condition; + std::mutex m_queue_mutex; + + EventBaseSP m_pending_notification_sp; + + // Maps known TIDs to stop (true) or not-stopped (false) state. + TIDBoolMap m_tid_stop_map; }; } |

