Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:54

0001 //===-- Queue.h ------------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_TARGET_QUEUE_H
0010 #define LLDB_TARGET_QUEUE_H
0011 
0012 #include <string>
0013 #include <vector>
0014 
0015 #include "lldb/Target/QueueItem.h"
0016 #include "lldb/lldb-enumerations.h"
0017 #include "lldb/lldb-forward.h"
0018 #include "lldb/lldb-private.h"
0019 
0020 namespace lldb_private {
0021 
0022 // Queue:
0023 // This class represents a libdispatch aka Grand Central Dispatch queue in the
0024 // process.
0025 //
0026 // A program using libdispatch will create queues, put work items
0027 // (functions, blocks) on the queues.  The system will create / reassign
0028 // pthreads to execute the work items for the queues.  A serial queue will be
0029 // associated with a single thread (or possibly no thread, if it is not doing
0030 // any work).  A concurrent queue may be associated with multiple threads.
0031 
0032 class Queue : public std::enable_shared_from_this<Queue> {
0033 public:
0034   Queue(lldb::ProcessSP process_sp, lldb::queue_id_t queue_id,
0035         const char *queue_name);
0036 
0037   ~Queue();
0038 
0039   /// Get the QueueID for this Queue
0040   ///
0041   /// A 64-bit ID number that uniquely identifies a queue at this particular
0042   /// stop_id.  Currently the libdispatch serialnum is used for the QueueID;
0043   /// it is a number that starts at 1 for each process and increments with
0044   /// each queue.  A serialnum is not reused for a different queue in the
0045   /// lifetime of that process execution.
0046   ///
0047   /// \return
0048   ///     The QueueID for this Queue.
0049   lldb::queue_id_t GetID();
0050 
0051   /// Get the name of this Queue
0052   ///
0053   /// \return
0054   ///     The name of the queue, if one is available.
0055   ///     A NULL pointer is returned if none is available.
0056   const char *GetName();
0057 
0058   /// Get the IndexID for this Queue
0059   ///
0060   /// This is currently the same as GetID().  If it changes in the future,
0061   /// it will be  a small integer value (starting with 1) assigned to
0062   /// each queue that is seen during a Process lifetime.
0063   ///
0064   /// Both the GetID and GetIndexID are being retained for Queues to
0065   /// maintain similar API to the Thread class, and allow for the
0066   /// possibility of GetID changing to a different source in the future.
0067   ///
0068   /// \return
0069   ///     The IndexID for this queue.
0070   uint32_t GetIndexID();
0071 
0072   /// Return the threads currently associated with this queue
0073   ///
0074   /// Zero, one, or many threads may be executing code for a queue at
0075   /// a given point in time.  This call returns the list of threads
0076   /// that are currently executing work for this queue.
0077   ///
0078   /// \return
0079   ///     The threads currently performing work for this queue
0080   std::vector<lldb::ThreadSP> GetThreads();
0081 
0082   /// Return the items that are currently enqueued
0083   ///
0084   /// "Enqueued" means that the item has been added to the queue to
0085   /// be done, but has not yet been done.  When the item is going to
0086   /// be processed it is "dequeued".
0087   ///
0088   /// \return
0089   ///     The vector of enqueued items for this queue
0090   const std::vector<lldb::QueueItemSP> &GetPendingItems();
0091 
0092   lldb::ProcessSP GetProcess() const { return m_process_wp.lock(); }
0093 
0094   /// Get the number of work items that this queue is currently running
0095   ///
0096   /// \return
0097   ///     The number of work items currently executing.  For a serial
0098   ///     queue, this will be 0 or 1.  For a concurrent queue, this
0099   ///     may be any number.
0100   uint32_t GetNumRunningWorkItems() const;
0101 
0102   /// Get the number of work items enqueued on this queue
0103   ///
0104   /// \return
0105   ///     The number of work items currently enqueued, waiting to
0106   ///     execute.
0107   uint32_t GetNumPendingWorkItems() const;
0108 
0109   /// Get the dispatch_queue_t structure address for this Queue
0110   ///
0111   /// Get the address in the inferior process' memory of this Queue's
0112   /// dispatch_queue_t structure.
0113   ///
0114   /// \return
0115   ///     The address of the dispatch_queue_t structure, if known.
0116   ///     LLDB_INVALID_ADDRESS will be returned if it is unavailable.
0117   lldb::addr_t GetLibdispatchQueueAddress() const;
0118 
0119   void SetNumRunningWorkItems(uint32_t count);
0120 
0121   void SetNumPendingWorkItems(uint32_t count);
0122 
0123   void SetLibdispatchQueueAddress(lldb::addr_t dispatch_queue_t_addr);
0124 
0125   void PushPendingQueueItem(lldb::QueueItemSP item) {
0126     m_pending_items.push_back(item);
0127   }
0128 
0129   /// Return the kind (serial, concurrent) of this queue.
0130   lldb::QueueKind GetKind();
0131 
0132   void SetKind(lldb::QueueKind kind);
0133 
0134 private:
0135   // For Queue only
0136 
0137   lldb::ProcessWP m_process_wp;
0138   lldb::queue_id_t m_queue_id;
0139   std::string m_queue_name;
0140   uint32_t m_running_work_items_count;
0141   uint32_t m_pending_work_items_count;
0142   std::vector<lldb::QueueItemSP> m_pending_items;
0143   lldb::addr_t m_dispatch_queue_t_addr; // address of libdispatch
0144                                         // dispatch_queue_t for this Queue
0145   lldb::QueueKind m_kind;
0146 
0147   Queue(const Queue &) = delete;
0148   const Queue &operator=(const Queue &) = delete;
0149 };
0150 
0151 } // namespace lldb_private
0152 
0153 #endif // LLDB_TARGET_QUEUE_H