lock.lock();
}
- int alive;
-
- do {
- alive = 0;
- for (size_t i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++) {
- if (m_ThreadStats[i].State != ThreadDead) {
- alive++;
- KillWorker();
- }
- }
+ for (size_t i = 0; i < sizeof(m_Threads) / sizeof(m_Threads[0]); i++) {
+ lock.unlock();
+ m_Threads[i].Thread.join();
+ lock.lock();
- if (alive > 0) {
- lock.unlock();
- Utility::Sleep(0.5);
- lock.lock();
- }
- } while (alive > 0);
+ m_Threads[i].State = ThreadDead;
+ }
m_ManagerThread.join();
m_StatsThread.join();
UpdateThreadUtilization(tid, ThreadIdle);
- while (m_WorkItems.empty() && !m_Stopped && !m_ThreadStats[tid].Zombie)
+ while (m_WorkItems.empty() && !m_Stopped && !m_Threads[tid].Zombie)
m_WorkCV.wait(lock);
- if (m_ThreadStats[tid].Zombie)
+ if (m_Threads[tid].Zombie)
break;
if (m_WorkItems.empty() && m_Stopped)
boost::mutex::scoped_lock lock(m_Mutex);
UpdateThreadUtilization(tid, ThreadDead);
- m_ThreadStats[tid].Zombie = false;
+ m_Threads[tid].Zombie = false;
}
/**
alive = 0;
- for (size_t i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++) {
- if (m_ThreadStats[i].State != ThreadDead && !m_ThreadStats[i].Zombie) {
+ for (size_t i = 0; i < sizeof(m_Threads) / sizeof(m_Threads[0]); i++) {
+ if (m_Threads[i].State != ThreadDead && !m_Threads[i].Zombie) {
alive++;
- utilization += m_ThreadStats[i].Utilization * 100;
+ utilization += m_Threads[i].Utilization * 100;
}
}
*/
void ThreadPool::SpawnWorker(void)
{
- for (size_t i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++) {
- if (m_ThreadStats[i].State == ThreadDead) {
+ for (size_t i = 0; i < sizeof(m_Threads) / sizeof(m_Threads[0]); i++) {
+ if (m_Threads[i].State == ThreadDead) {
Log(LogDebug, "debug", "Spawning worker thread.");
- m_ThreadStats[i] = ThreadStats(ThreadIdle);
- boost::thread worker(boost::bind(&ThreadPool::QueueThreadProc, this, i));
- worker.detach();
+ m_Threads[i].State = ThreadIdle;
+
+ boost::thread thread(boost::bind(&ThreadPool::QueueThreadProc, this, i));
+ m_Threads[i].Thread = boost::move(thread);
break;
}
*/
void ThreadPool::KillWorker(void)
{
- for (size_t i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++) {
- if (m_ThreadStats[i].State == ThreadIdle && !m_ThreadStats[i].Zombie) {
+ for (size_t i = 0; i < sizeof(m_Threads) / sizeof(m_Threads[0]); i++) {
+ if (m_Threads[i].State == ThreadIdle && !m_Threads[i].Zombie) {
Log(LogDebug, "base", "Killing worker thread.");
- m_ThreadStats[i].Zombie = true;
+ m_Threads[i].Zombie = true;
m_WorkCV.notify_all();
break;
if (m_Stopped)
break;
- for (size_t i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++)
+ for (size_t i = 0; i < sizeof(m_Threads) / sizeof(m_Threads[0]); i++)
UpdateThreadUtilization(i);
}
}
{
double utilization;
- switch (m_ThreadStats[tid].State) {
+ switch (m_Threads[tid].State) {
case ThreadDead:
return;
case ThreadIdle:
}
double now = Utility::GetTime();
- double time = now - m_ThreadStats[tid].LastUpdate;
+ double time = now - m_Threads[tid].LastUpdate;
const double avg_time = 5.0;
if (time > avg_time)
time = avg_time;
- m_ThreadStats[tid].Utilization = (m_ThreadStats[tid].Utilization * (avg_time - time) + utilization * time) / avg_time;
- m_ThreadStats[tid].LastUpdate = now;
+ m_Threads[tid].Utilization = (m_Threads[tid].Utilization * (avg_time - time) + utilization * time) / avg_time;
+ m_Threads[tid].LastUpdate = now;
if (state != ThreadUnspecified)
- m_ThreadStats[tid].State = state;
+ m_Threads[tid].State = state;
}