1 //===-- MICmnThreadMgrStd.cpp -----------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 #include "MICmnThreadMgrStd.h"
12 #include "MICmnResources.h"
13 #include "MIUtilSingletonHelper.h"
16 // Details: CMICmnThreadMgr constructor.
22 CMICmnThreadMgrStd::CMICmnThreadMgrStd() {}
25 // Details: CMICmnThreadMgr destructor.
31 CMICmnThreadMgrStd::~CMICmnThreadMgrStd() { Shutdown(); }
34 // Details: Initialise resources for *this thread manager.
37 // Return: MIstatus::success - Functional succeeded.
38 // MIstatus::failure - Functional failed.
41 bool CMICmnThreadMgrStd::Initialize() {
42 m_clientUsageRefCnt++;
45 return MIstatus::success;
47 bool bOk = MIstatus::success;
49 ClrErrorDescription();
52 // Note initialisation order is important here as some resources depend on
54 MI::ModuleInit<CMICmnLog>(IDS_MI_INIT_ERR_LOG, bOk, errMsg);
55 MI::ModuleInit<CMICmnResources>(IDS_MI_INIT_ERR_RESOURCES, bOk, errMsg);
60 CMIUtilString strInitError(CMIUtilString::Format(
61 MIRSRC(IDS_MI_INIT_ERR_THREADMGR), errMsg.c_str()));
62 SetErrorDescription(strInitError);
63 return MIstatus::failure;
70 // Details: Release resources for *this thread manager.
73 // Return: MIstatus::success - Functional succeeded.
74 // MIstatus::failure - Functional failed.
77 bool CMICmnThreadMgrStd::Shutdown() {
78 if (--m_clientUsageRefCnt > 0)
79 return MIstatus::success;
82 return MIstatus::success;
84 m_bInitialized = false;
86 ClrErrorDescription();
88 bool bOk = MIstatus::success;
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);
99 SetErrorDescriptionn(MIRSRC(IDS_MI_SHUTDOWN_ERR), errMsg.c_str());
106 // Details: Ask the thread manager to kill all threads and wait until they have
110 // Return: MIstatus::success - Functional succeeded.
111 // MIstatus::failure - Functional failed.
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();
123 // Wait for this thread to die
124 pThread->ThreadJoin();
128 return MIstatus::success;
132 // Details: Add a thread object to *this manager's list of thread objects. The
134 // used to manage thread objects centrally.
136 // Args: vrObj - (R) A thread object.
137 // Return: MIstatus::success - Functional succeeded.
138 // MIstatus::failure - Functional failed.
141 bool CMICmnThreadMgrStd::AddThread(const CMIUtilThreadActiveObjBase &vrObj) {
142 m_threadList.push_back(const_cast<CMIUtilThreadActiveObjBase *>(&vrObj));
144 return MIstatus::success;