ThreadSpec.h revision 649492b3614c11e52a2dbe3693bbdf97efec9ba0
1//===-- ThreadSpec.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_ThreadSpec_h_
11#define liblldb_ThreadSpec_h_
12
13#include <map>
14#include <string>
15
16#include "lldb/lldb-private.h"
17
18namespace lldb_private {
19
20// Note: For now the thread spec has only fixed elements -
21//   Thread ID
22//   Thread Index
23//   Thread Name
24//   Thread Queue Name
25//
26//  But if we need more generality, we can hang a key/value map off of this structure.
27//  That's why the thread matches spec test is done as a virtual method in Thread::MatchesSpec,
28//  since it is the native thread that would know how to interpret the keys.
29//  I was going to do the Queue Name this way out of sheer orneriness, but that seems a
30//  sufficiently general concept, so I put it in here on its own.
31
32class ThreadSpec
33{
34public:
35    ThreadSpec ();
36
37    ThreadSpec (const ThreadSpec &rhs);
38
39    const ThreadSpec &
40    operator=(const ThreadSpec &rhs);
41
42    void
43    SetIndex (uint32_t index)
44    {
45        m_index = index;
46    }
47
48    void
49    SetTID   (lldb::tid_t tid)
50    {
51        m_tid = tid;
52    }
53
54    void
55    SetName (const char *name)
56    {
57        m_name = name;
58    }
59
60    void
61    SetQueueName (const char *queue_name)
62    {
63        m_queue_name = queue_name;
64    }
65
66    uint32_t
67    GetIndex () const
68    {
69        return m_index;
70    }
71
72    lldb::tid_t
73    GetTID () const
74    {
75        return m_tid;
76    }
77
78    const char *
79    GetName () const;
80
81    const char *
82    GetQueueName () const;
83
84    bool
85    TIDMatches (lldb::tid_t thread_id) const
86    {
87        if (m_tid == LLDB_INVALID_THREAD_ID || thread_id == LLDB_INVALID_THREAD_ID)
88            return true;
89        else
90            return thread_id == m_tid;
91    }
92
93    bool
94    IndexMatches (uint32_t index) const
95    {
96        if (m_index == -1 || index == -1)
97            return true;
98        else
99            return index == m_index;
100    }
101
102    bool
103    NameMatches (const char *name) const
104    {
105        if (m_name.empty())
106            return true;
107        else if (name == NULL)
108            return false;
109        else
110            return m_name == name;
111    }
112
113    bool
114    QueueNameMatches (const char *queue_name) const
115    {
116        if (m_queue_name.empty())
117            return true;
118        else if (queue_name == NULL)
119            return false;
120        else
121            return m_queue_name == queue_name;
122    }
123
124    bool
125    ThreadPassesBasicTests (Thread *thread) const;
126
127    bool
128    HasSpecification () const;
129
130    void
131    GetDescription (Stream *s, lldb::DescriptionLevel level) const;
132
133protected:
134private:
135    uint32_t m_index;
136    lldb::tid_t m_tid;
137    std::string m_name;
138    std::string m_queue_name;
139};
140
141} // namespace lldb_private
142
143#endif  // liblldb_ThreadSpec_h_
144