1 //===-- MICmnThreadMgr.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 // File: MICmnThreadMgr.cpp
13 // Overview: CMICmnThreadMgr implementation.
15 // Environment: Compilers: Visual C++ 12.
16 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 // Libraries: See MIReadmetxt.
23 #include "MICmnThreadMgrStd.h"
25 #include "MICmnResources.h"
26 #include "MIUtilSingletonHelper.h"
28 //++ ------------------------------------------------------------------------------------
29 // Details: CMICmnThreadMgr constructor.
35 CMICmnThreadMgrStd::CMICmnThreadMgrStd(void)
39 //++ ------------------------------------------------------------------------------------
40 // Details: CMICmnThreadMgr destructor.
46 CMICmnThreadMgrStd::~CMICmnThreadMgrStd(void)
51 //++ ------------------------------------------------------------------------------------
52 // Details: Initialise resources for *this thread manager.
55 // Return: MIstatus::success - Functional succeeded.
56 // MIstatus::failure - Functional failed.
60 CMICmnThreadMgrStd::Initialize(void)
62 m_clientUsageRefCnt++;
65 return MIstatus::success;
67 bool bOk = MIstatus::success;
69 ClrErrorDescription();
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);
80 CMIUtilString strInitError(CMIUtilString::Format(MIRSRC(IDS_MI_INIT_ERR_THREADMGR), errMsg.c_str()));
81 SetErrorDescription(strInitError);
82 return MIstatus::failure;
88 //++ ------------------------------------------------------------------------------------
89 // Details: Release resources for *this thread manager.
92 // Return: MIstatus::success - Functional succeeded.
93 // MIstatus::failure - Functional failed.
97 CMICmnThreadMgrStd::Shutdown(void)
99 if (--m_clientUsageRefCnt > 0)
100 return MIstatus::success;
103 return MIstatus::success;
105 m_bInitialized = false;
107 ClrErrorDescription();
109 bool bOk = MIstatus::success;
110 CMIUtilString errMsg;
113 ThreadAllTerminate();
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);
121 SetErrorDescriptionn(MIRSRC(IDS_MI_SHUTDOWN_ERR), errMsg.c_str());
127 //++ ------------------------------------------------------------------------------------
128 // Details: Ask the thread manager to kill all threads and wait until they have died
131 // Return: MIstatus::success - Functional succeeded.
132 // MIstatus::failure - Functional failed.
136 CMICmnThreadMgrStd::ThreadAllTerminate(void)
138 ThreadList_t::const_iterator it = m_threadList.begin();
139 for (; it != m_threadList.end(); ++it)
141 // If the thread is still running
142 CMIUtilThreadActiveObjBase *pThread = *it;
143 if (pThread->ThreadIsActive())
145 // Ask this thread to kill itself
146 pThread->ThreadKill();
148 // Wait for this thread to die
149 pThread->ThreadJoin();
153 return MIstatus::success;
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.
160 // Args: vrObj - (R) A thread object.
161 // Return: MIstatus::success - Functional succeeded.
162 // MIstatus::failure - Functional failed.
166 CMICmnThreadMgrStd::AddThread(const CMIUtilThreadActiveObjBase &vrObj)
168 m_threadList.push_back(const_cast<CMIUtilThreadActiveObjBase *>(&vrObj));
170 return MIstatus::success;