]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/tools/lldb-mi/MICmnThreadMgrStd.cpp
Unbreak DRM KMS build by adding the needed compatibility field in the LinuxKPI.
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / tools / lldb-mi / MICmnThreadMgrStd.cpp
1 //===-- MICmnThreadMgrStd.cpp -----------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // In-house headers:
10 #include "MICmnThreadMgrStd.h"
11 #include "MICmnLog.h"
12 #include "MICmnResources.h"
13 #include "MIUtilSingletonHelper.h"
14
15 //++
16 // Details: CMICmnThreadMgr constructor.
17 // Type:    Method.
18 // Args:    None.
19 // Return:  None.
20 // Throws:  None.
21 //--
22 CMICmnThreadMgrStd::CMICmnThreadMgrStd() {}
23
24 //++
25 // Details: CMICmnThreadMgr destructor.
26 // Type:    Method.
27 // Args:    None.
28 // Return:  None.
29 // Throws:  None.
30 //--
31 CMICmnThreadMgrStd::~CMICmnThreadMgrStd() { Shutdown(); }
32
33 //++
34 // Details: Initialise resources for *this thread manager.
35 // Type:    Method.
36 // Args:    None.
37 // Return:  MIstatus::success - Functional succeeded.
38 //          MIstatus::failure - Functional failed.
39 // Throws:  None.
40 //--
41 bool CMICmnThreadMgrStd::Initialize() {
42   m_clientUsageRefCnt++;
43
44   if (m_bInitialized)
45     return MIstatus::success;
46
47   bool bOk = MIstatus::success;
48
49   ClrErrorDescription();
50   CMIUtilString errMsg;
51
52   // Note initialisation order is important here as some resources depend on
53   // previous
54   MI::ModuleInit<CMICmnLog>(IDS_MI_INIT_ERR_LOG, bOk, errMsg);
55   MI::ModuleInit<CMICmnResources>(IDS_MI_INIT_ERR_RESOURCES, bOk, errMsg);
56
57   m_bInitialized = bOk;
58
59   if (!bOk) {
60     CMIUtilString strInitError(CMIUtilString::Format(
61         MIRSRC(IDS_MI_INIT_ERR_THREADMGR), errMsg.c_str()));
62     SetErrorDescription(strInitError);
63     return MIstatus::failure;
64   }
65
66   return bOk;
67 }
68
69 //++
70 // Details: Release resources for *this thread manager.
71 // Type:    Method.
72 // Args:    None.
73 // Return:  MIstatus::success - Functional succeeded.
74 //          MIstatus::failure - Functional failed.
75 // Throws:  None.
76 //--
77 bool CMICmnThreadMgrStd::Shutdown() {
78   if (--m_clientUsageRefCnt > 0)
79     return MIstatus::success;
80
81   if (!m_bInitialized)
82     return MIstatus::success;
83
84   m_bInitialized = false;
85
86   ClrErrorDescription();
87
88   bool bOk = MIstatus::success;
89   CMIUtilString errMsg;
90
91   // Tidy up
92   ThreadAllTerminate();
93
94   // Note shutdown order is important here
95   MI::ModuleShutdown<CMICmnResources>(IDE_MI_SHTDWN_ERR_RESOURCES, bOk, errMsg);
96   MI::ModuleShutdown<CMICmnLog>(IDS_MI_SHTDWN_ERR_LOG, bOk, errMsg);
97
98   if (!bOk) {
99     SetErrorDescriptionn(MIRSRC(IDS_MI_SHUTDOWN_ERR), errMsg.c_str());
100   }
101
102   return bOk;
103 }
104
105 //++
106 // Details: Ask the thread manager to kill all threads and wait until they have
107 // died
108 // Type:    Method.
109 // Args:    None.
110 // Return:  MIstatus::success - Functional succeeded.
111 //          MIstatus::failure - Functional failed.
112 // Throws:  None.
113 //--
114 bool CMICmnThreadMgrStd::ThreadAllTerminate() {
115   ThreadList_t::const_iterator it = m_threadList.begin();
116   for (; it != m_threadList.end(); ++it) {
117     // If the thread is still running
118     CMIUtilThreadActiveObjBase *pThread = *it;
119     if (pThread->ThreadIsActive()) {
120       // Ask this thread to kill itself
121       pThread->ThreadKill();
122
123       // Wait for this thread to die
124       pThread->ThreadJoin();
125     }
126   }
127
128   return MIstatus::success;
129 }
130
131 //++
132 // Details: Add a thread object to *this manager's list of thread objects. The
133 // list to
134 //          used to manage thread objects centrally.
135 // Type:    Method.
136 // Args:    vrObj   - (R) A thread object.
137 // Return:  MIstatus::success - Functional succeeded.
138 //          MIstatus::failure - Functional failed.
139 // Throws:  None.
140 //--
141 bool CMICmnThreadMgrStd::AddThread(const CMIUtilThreadActiveObjBase &vrObj) {
142   m_threadList.push_back(const_cast<CMIUtilThreadActiveObjBase *>(&vrObj));
143
144   return MIstatus::success;
145 }