]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmnThreadMgrStd.cpp
MFV r288408:
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmnThreadMgrStd.cpp
1 //===-- MICmnThreadMgr.cpp --------------------------------------*- 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 //++
11 // File:        MICmnThreadMgr.cpp
12 //
13 // Overview:    CMICmnThreadMgr implementation.
14 //
15 // Environment: Compilers:  Visual C++ 12.
16 //                          gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 //              Libraries:  See MIReadmetxt.
18 //
19 // Copyright:   None.
20 //--
21
22 // In-house headers:
23 #include "MICmnThreadMgrStd.h"
24 #include "MICmnLog.h"
25 #include "MICmnResources.h"
26 #include "MIUtilSingletonHelper.h"
27
28 //++ ------------------------------------------------------------------------------------
29 // Details: CMICmnThreadMgr constructor.
30 // Type:    Method.
31 // Args:    None.
32 // Return:  None.
33 // Throws:  None.
34 //--
35 CMICmnThreadMgrStd::CMICmnThreadMgrStd(void)
36 {
37 }
38
39 //++ ------------------------------------------------------------------------------------
40 // Details: CMICmnThreadMgr destructor.
41 // Type:    Method.
42 // Args:    None.
43 // Return:  None.
44 // Throws:  None.
45 //--
46 CMICmnThreadMgrStd::~CMICmnThreadMgrStd(void)
47 {
48     Shutdown();
49 }
50
51 //++ ------------------------------------------------------------------------------------
52 // Details: Initialise resources for *this thread manager.
53 // Type:    Method.
54 // Args:    None.
55 // Return:  MIstatus::success - Functional succeeded.
56 //          MIstatus::failure - Functional failed.
57 // Throws:  None.
58 //--
59 bool
60 CMICmnThreadMgrStd::Initialize(void)
61 {
62     m_clientUsageRefCnt++;
63
64     if (m_bInitialized)
65         return MIstatus::success;
66
67     bool bOk = MIstatus::success;
68
69     ClrErrorDescription();
70     CMIUtilString errMsg;
71
72     // Note initialisation order is important here as some resources depend on previous
73     MI::ModuleInit<CMICmnLog>(IDS_MI_INIT_ERR_LOG, bOk, errMsg);
74     MI::ModuleInit<CMICmnResources>(IDS_MI_INIT_ERR_RESOURCES, bOk, errMsg);
75
76     m_bInitialized = bOk;
77
78     if (!bOk)
79     {
80         CMIUtilString strInitError(CMIUtilString::Format(MIRSRC(IDS_MI_INIT_ERR_THREADMGR), errMsg.c_str()));
81         SetErrorDescription(strInitError);
82         return MIstatus::failure;
83     }
84
85     return bOk;
86 }
87
88 //++ ------------------------------------------------------------------------------------
89 // Details: Release resources for *this thread manager.
90 // Type:    Method.
91 // Args:    None.
92 // Return:  MIstatus::success - Functional succeeded.
93 //          MIstatus::failure - Functional failed.
94 // Throws:  None.
95 //--
96 bool
97 CMICmnThreadMgrStd::Shutdown(void)
98 {
99     if (--m_clientUsageRefCnt > 0)
100         return MIstatus::success;
101
102     if (!m_bInitialized)
103         return MIstatus::success;
104
105     m_bInitialized = false;
106
107     ClrErrorDescription();
108
109     bool bOk = MIstatus::success;
110     CMIUtilString errMsg;
111
112     // Tidy up
113     ThreadAllTerminate();
114
115     // Note shutdown order is important here
116     MI::ModuleShutdown<CMICmnResources>(IDE_MI_SHTDWN_ERR_RESOURCES, bOk, errMsg);
117     MI::ModuleShutdown<CMICmnLog>(IDS_MI_SHTDWN_ERR_LOG, bOk, errMsg);
118
119     if (!bOk)
120     {
121         SetErrorDescriptionn(MIRSRC(IDS_MI_SHUTDOWN_ERR), errMsg.c_str());
122     }
123
124     return bOk;
125 }
126
127 //++ ------------------------------------------------------------------------------------
128 // Details: Ask the thread manager to kill all threads and wait until they have died
129 // Type:    Method.
130 // Args:    None.
131 // Return:  MIstatus::success - Functional succeeded.
132 //          MIstatus::failure - Functional failed.
133 // Throws:  None.
134 //--
135 bool
136 CMICmnThreadMgrStd::ThreadAllTerminate(void)
137 {
138     ThreadList_t::const_iterator it = m_threadList.begin();
139     for (; it != m_threadList.end(); ++it)
140     {
141         // If the thread is still running
142         CMIUtilThreadActiveObjBase *pThread = *it;
143         if (pThread->ThreadIsActive())
144         {
145             // Ask this thread to kill itself
146             pThread->ThreadKill();
147
148             // Wait for this thread to die
149             pThread->ThreadJoin();
150         }
151     }
152
153     return MIstatus::success;
154 }
155
156 //++ ------------------------------------------------------------------------------------
157 // Details: Add a thread object to *this manager's list of thread objects. The list to
158 //          used to manage thread objects centrally.
159 // Type:    Method.
160 // Args:    vrObj   - (R) A thread object.
161 // Return:  MIstatus::success - Functional succeeded.
162 //          MIstatus::failure - Functional failed.
163 // Throws:  None.
164 //--
165 bool
166 CMICmnThreadMgrStd::AddThread(const CMIUtilThreadActiveObjBase &vrObj)
167 {
168     m_threadList.push_back(const_cast<CMIUtilThreadActiveObjBase *>(&vrObj));
169
170     return MIstatus::success;
171 }