1262182Semaste//===-- Queue.h ------------------------------------------------*- C++ -*-===// 2262182Semaste// 3262182Semaste// The LLVM Compiler Infrastructure 4262182Semaste// 5262182Semaste// This file is distributed under the University of Illinois Open Source 6262182Semaste// License. See LICENSE.TXT for details. 7262182Semaste// 8262182Semaste//===----------------------------------------------------------------------===// 9262182Semaste 10262182Semaste#ifndef liblldb_Queue_h_ 11262182Semaste#define liblldb_Queue_h_ 12262182Semaste 13262182Semaste#include <vector> 14262182Semaste#include <string> 15262182Semaste 16262182Semaste#include "lldb/lldb-forward.h" 17262182Semaste#include "lldb/lldb-enumerations.h" 18262182Semaste#include "lldb/lldb-private.h" 19262182Semaste#include "lldb/Target/QueueItem.h" 20262182Semaste 21262182Semaste 22262182Semastenamespace lldb_private { 23262182Semaste 24262182Semaste//------------------------------------------------------------------ 25262182Semaste// Queue: 26262182Semaste// This class represents a libdispatch aka Grand Central Dispatch 27262182Semaste// queue in the process. 28262182Semaste// 29262182Semaste// A program using libdispatch will create queues, put work items 30262182Semaste// (functions, blocks) on the queues. The system will create / 31262182Semaste// reassign pthreads to execute the work items for the queues. A 32262182Semaste// serial queue will be associated with a single thread (or possibly 33262182Semaste// no thread, if it is not doing any work). A concurrent queue may 34262182Semaste// be associated with multiple threads. 35262182Semaste//------------------------------------------------------------------ 36262182Semaste 37262182Semaste 38262182Semasteclass Queue : 39262182Semaste public std::enable_shared_from_this<Queue> 40262182Semaste{ 41262182Semastepublic: 42262182Semaste 43262182Semaste Queue (lldb::ProcessSP process_sp, lldb::queue_id_t queue_id, const char *queue_name); 44262182Semaste 45262182Semaste ~Queue (); 46262182Semaste 47262182Semaste //------------------------------------------------------------------ 48262182Semaste /// Get the QueueID for this Queue 49262182Semaste /// 50262182Semaste /// A 64-bit ID number that uniquely identifies a queue at this particular 51262182Semaste /// stop_id. Currently the libdispatch serialnum is used for the QueueID; 52262182Semaste /// it is a number that starts at 1 for each process and increments with 53262182Semaste /// each queue. A serialnum is not reused for a different queue in the 54262182Semaste /// lifetime of that process execution. 55262182Semaste /// 56262182Semaste /// @return 57262182Semaste /// The QueueID for this Queue. 58262182Semaste //------------------------------------------------------------------ 59262182Semaste lldb::queue_id_t 60262182Semaste GetID (); 61262182Semaste 62262182Semaste //------------------------------------------------------------------ 63262182Semaste /// Get the name of this Queue 64262182Semaste /// 65262182Semaste /// @return 66262182Semaste /// The name of the queue, if one is available. 67262182Semaste /// A NULL pointer is returned if none is available. 68262182Semaste //------------------------------------------------------------------ 69262182Semaste const char * 70262182Semaste GetName (); 71262182Semaste 72262182Semaste //------------------------------------------------------------------ 73262182Semaste /// Get the IndexID for this Queue 74262182Semaste /// 75262182Semaste /// This is currently the same as GetID(). If it changes in the future, 76262182Semaste /// it will be a small integer value (starting with 1) assigned to 77262182Semaste /// each queue that is seen during a Process lifetime. 78262182Semaste /// 79262182Semaste /// Both the GetID and GetIndexID are being retained for Queues to 80262182Semaste /// maintain similar API to the Thread class, and allow for the 81262182Semaste /// possibility of GetID changing to a different source in the future. 82262182Semaste /// 83262182Semaste /// @return 84262182Semaste /// The IndexID for this queue. 85262182Semaste //------------------------------------------------------------------ 86262182Semaste uint32_t 87262182Semaste GetIndexID (); 88262182Semaste 89262182Semaste //------------------------------------------------------------------ 90262182Semaste /// Return the threads currently associated with this queue 91262182Semaste /// 92262182Semaste /// Zero, one, or many threads may be executing code for a queue at 93262182Semaste /// a given point in time. This call returns the list of threads 94262182Semaste /// that are currently executing work for this queue. 95262182Semaste /// 96262182Semaste /// @return 97262182Semaste /// The threads currently performing work for this queue 98262182Semaste //------------------------------------------------------------------ 99262182Semaste std::vector<lldb::ThreadSP> 100262182Semaste GetThreads (); 101262182Semaste 102262182Semaste //------------------------------------------------------------------ 103262182Semaste /// Return the items that are currently enqueued 104262182Semaste /// 105262182Semaste /// "Enqueued" means that the item has been added to the queue to 106262182Semaste /// be done, but has not yet been done. When the item is going to 107262182Semaste /// be processed it is "dequeued". 108262182Semaste /// 109262182Semaste /// @return 110262182Semaste /// The vector of enqueued items for this queue 111262182Semaste //------------------------------------------------------------------ 112262182Semaste const std::vector<lldb::QueueItemSP> & 113262182Semaste GetPendingItems(); 114262182Semaste 115262182Semaste lldb::ProcessSP 116262182Semaste GetProcess() const 117262182Semaste { 118262182Semaste return m_process_wp.lock(); 119262182Semaste } 120262182Semaste 121262182Semaste //------------------------------------------------------------------ 122262182Semaste /// Get the number of work items that this queue is currently running 123262182Semaste /// 124262182Semaste /// @return 125262182Semaste /// The number of work items currently executing. For a serial 126262182Semaste /// queue, this will be 0 or 1. For a concurrent queue, this 127262182Semaste /// may be any number. 128262182Semaste //------------------------------------------------------------------ 129262182Semaste uint32_t 130262182Semaste GetNumRunningWorkItems () const; 131262182Semaste 132262182Semaste //------------------------------------------------------------------ 133262182Semaste /// Get the number of work items enqueued on this queue 134262182Semaste /// 135262182Semaste /// @return 136262182Semaste /// The number of work items currently enqueued, waiting to 137262182Semaste /// execute. 138262182Semaste //------------------------------------------------------------------ 139262182Semaste uint32_t 140262182Semaste GetNumPendingWorkItems () const; 141262182Semaste 142262182Semaste //------------------------------------------------------------------ 143262182Semaste /// Get the dispatch_queue_t structure address for this Queue 144262182Semaste /// 145262182Semaste /// Get the address in the inferior process' memory of this Queue's 146262182Semaste /// dispatch_queue_t structure. 147262182Semaste /// 148262182Semaste /// @return 149262182Semaste /// The address of the dispatch_queue_t structure, if known. 150262182Semaste /// LLDB_INVALID_ADDRESS will be returned if it is unavailable. 151262182Semaste //------------------------------------------------------------------ 152262182Semaste lldb::addr_t 153262182Semaste GetLibdispatchQueueAddress () const; 154262182Semaste 155262182Semaste 156262182Semaste void 157262182Semaste SetNumRunningWorkItems (uint32_t count); 158262182Semaste 159262182Semaste void 160262182Semaste SetNumPendingWorkItems (uint32_t count); 161262182Semaste 162262182Semaste void 163262182Semaste SetLibdispatchQueueAddress (lldb::addr_t dispatch_queue_t_addr); 164262182Semaste 165262182Semaste void 166262182Semaste PushPendingQueueItem (lldb::QueueItemSP item) 167262182Semaste { 168262182Semaste m_pending_items.push_back (item); 169262182Semaste } 170262182Semaste 171262182Semasteprivate: 172262182Semaste //------------------------------------------------------------------ 173262182Semaste // For Queue only 174262182Semaste //------------------------------------------------------------------ 175262182Semaste 176262182Semaste lldb::ProcessWP m_process_wp; 177262182Semaste lldb::queue_id_t m_queue_id; 178262182Semaste std::string m_queue_name; 179262182Semaste uint32_t m_running_work_items_count; 180262182Semaste uint32_t m_pending_work_items_count; 181262182Semaste std::vector<lldb::QueueItemSP> m_pending_items; 182262182Semaste lldb::addr_t m_dispatch_queue_t_addr; // address of libdispatch dispatch_queue_t for this Queue 183262182Semaste 184262182Semaste DISALLOW_COPY_AND_ASSIGN (Queue); 185262182Semaste}; 186262182Semaste 187262182Semaste} // namespace lldb_private 188262182Semaste 189262182Semaste#endif // liblldb_Queue_h_ 190