ThreadList.h revision ccd5c4ee85d1592f9ae3da02c85f5647ca02fab2
1//===-- ThreadList.h --------------------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_ThreadList_h_
11#define liblldb_ThreadList_h_
12
13#include <vector>
14
15#include "lldb/lldb-private.h"
16#include "lldb/Host/Mutex.h"
17#include "lldb/Core/UserID.h"
18
19
20// FIXME: Currently this is a thread list with lots of functionality for use only by
21// the process for which this is the thread list.  If we ever want a container class
22// to hand out that is just a random subset of threads, with iterator functionality,
23// then we should make that part a base class, and make a ProcessThreadList for the
24// process.
25namespace lldb_private {
26
27class ThreadList
28{
29friend class Process;
30
31public:
32
33    ThreadList (Process *process);
34
35    ThreadList (const ThreadList &rhs);
36
37    ~ThreadList ();
38
39    const ThreadList&
40    operator = (const ThreadList& rhs);
41
42    uint32_t
43    GetSize(bool can_update = true);
44
45    void
46    AddThread (const lldb::ThreadSP &thread_sp);
47
48    // Return the selected thread if there is one.  Otherwise, return the thread
49    // selected at index 0.
50    lldb::ThreadSP
51    GetSelectedThread ();
52
53    bool
54    SetSelectedThreadByID (lldb::tid_t tid, bool notify = false);
55
56    bool
57    SetSelectedThreadByIndexID (uint32_t index_id, bool notify = false);
58
59    void
60    Clear();
61
62    void
63    Flush();
64
65    void
66    Destroy();
67
68    // Note that "idx" is not the same as the "thread_index". It is a zero
69    // based index to accessing the current threads, whereas "thread_index"
70    // is a unique index assigned
71    lldb::ThreadSP
72    GetThreadAtIndex (uint32_t idx, bool can_update = true);
73
74    lldb::ThreadSP
75    FindThreadByID (lldb::tid_t tid, bool can_update = true);
76
77    lldb::ThreadSP
78    RemoveThreadByID (lldb::tid_t tid, bool can_update = true);
79
80    lldb::ThreadSP
81    FindThreadByIndexID (uint32_t index_id, bool can_update = true);
82
83    lldb::ThreadSP
84    GetThreadSPForThreadPtr (Thread *thread_ptr);
85
86    bool
87    ShouldStop (Event *event_ptr);
88
89    Vote
90    ShouldReportStop (Event *event_ptr);
91
92    Vote
93    ShouldReportRun (Event *event_ptr);
94
95    void
96    RefreshStateAfterStop ();
97
98    //------------------------------------------------------------------
99    /// The thread list asks tells all the threads it is about to resume.
100    /// If a thread can "resume" without having to resume the target, it
101    /// will return false for WillResume, and then the process will not be
102    /// restarted.
103    ///
104    /// @return
105    ///    \b true instructs the process to resume normally,
106    ///    \b false means start & stopped events will be generated, but
107    ///    the process will not actually run.  The thread must then return
108    ///    the correct StopInfo when asked.
109    ///
110    //------------------------------------------------------------------
111    bool
112    WillResume ();
113
114    void
115    DidResume ();
116
117    void
118    DiscardThreadPlans();
119
120    uint32_t
121    GetStopID () const;
122
123    void
124    SetStopID (uint32_t stop_id);
125
126    Mutex &
127    GetMutex ()
128    {
129        return m_threads_mutex;
130    }
131
132    void
133    Update (ThreadList &rhs);
134
135protected:
136
137    void
138    NotifySelectedThreadChanged (lldb::tid_t tid);
139
140    typedef std::vector<lldb::ThreadSP> collection;
141    //------------------------------------------------------------------
142    // Classes that inherit from Process can see and modify these
143    //------------------------------------------------------------------
144    Process *m_process; ///< The process that manages this thread list.
145    uint32_t m_stop_id; ///< The process stop ID that this thread list is valid for.
146    collection m_threads; ///< The threads for this process.
147    mutable Mutex m_threads_mutex;
148    lldb::tid_t m_selected_tid;  ///< For targets that need the notion of a current thread.
149
150private:
151    ThreadList ();
152};
153
154} // namespace lldb_private
155
156#endif  // liblldb_ThreadList_h_
157