1 //===-- MICmnThreadMgrStd.cpp -----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 #include "MICmnThreadMgrStd.h"
13 #include "MICmnResources.h"
14 #include "MIUtilSingletonHelper.h"
17 //------------------------------------------------------------------------------------
18 // Details: CMICmnThreadMgr constructor.
24 CMICmnThreadMgrStd::CMICmnThreadMgrStd() {}
27 //------------------------------------------------------------------------------------
28 // Details: CMICmnThreadMgr destructor.
34 CMICmnThreadMgrStd::~CMICmnThreadMgrStd() { Shutdown(); }
37 //------------------------------------------------------------------------------------
38 // Details: Initialise resources for *this thread manager.
41 // Return: MIstatus::success - Functional succeeded.
42 // MIstatus::failure - Functional failed.
45 bool CMICmnThreadMgrStd::Initialize() {
46 m_clientUsageRefCnt++;
49 return MIstatus::success;
51 bool bOk = MIstatus::success;
53 ClrErrorDescription();
56 // Note initialisation order is important here as some resources depend on
58 MI::ModuleInit<CMICmnLog>(IDS_MI_INIT_ERR_LOG, bOk, errMsg);
59 MI::ModuleInit<CMICmnResources>(IDS_MI_INIT_ERR_RESOURCES, bOk, errMsg);
64 CMIUtilString strInitError(CMIUtilString::Format(
65 MIRSRC(IDS_MI_INIT_ERR_THREADMGR), errMsg.c_str()));
66 SetErrorDescription(strInitError);
67 return MIstatus::failure;
74 //------------------------------------------------------------------------------------
75 // Details: Release resources for *this thread manager.
78 // Return: MIstatus::success - Functional succeeded.
79 // MIstatus::failure - Functional failed.
82 bool CMICmnThreadMgrStd::Shutdown() {
83 if (--m_clientUsageRefCnt > 0)
84 return MIstatus::success;
87 return MIstatus::success;
89 m_bInitialized = false;
91 ClrErrorDescription();
93 bool bOk = MIstatus::success;
99 // Note shutdown order is important here
100 MI::ModuleShutdown<CMICmnResources>(IDE_MI_SHTDWN_ERR_RESOURCES, bOk, errMsg);
101 MI::ModuleShutdown<CMICmnLog>(IDS_MI_SHTDWN_ERR_LOG, bOk, errMsg);
104 SetErrorDescriptionn(MIRSRC(IDS_MI_SHUTDOWN_ERR), errMsg.c_str());
111 //------------------------------------------------------------------------------------
112 // Details: Ask the thread manager to kill all threads and wait until they have
116 // Return: MIstatus::success - Functional succeeded.
117 // MIstatus::failure - Functional failed.
120 bool CMICmnThreadMgrStd::ThreadAllTerminate() {
121 ThreadList_t::const_iterator it = m_threadList.begin();
122 for (; it != m_threadList.end(); ++it) {
123 // If the thread is still running
124 CMIUtilThreadActiveObjBase *pThread = *it;
125 if (pThread->ThreadIsActive()) {
126 // Ask this thread to kill itself
127 pThread->ThreadKill();
129 // Wait for this thread to die
130 pThread->ThreadJoin();
134 return MIstatus::success;
138 //------------------------------------------------------------------------------------
139 // Details: Add a thread object to *this manager's list of thread objects. The
141 // used to manage thread objects centrally.
143 // Args: vrObj - (R) A thread object.
144 // Return: MIstatus::success - Functional succeeded.
145 // MIstatus::failure - Functional failed.
148 bool CMICmnThreadMgrStd::AddThread(const CMIUtilThreadActiveObjBase &vrObj) {
149 m_threadList.push_back(const_cast<CMIUtilThreadActiveObjBase *>(&vrObj));
151 return MIstatus::success;