added: to thread manager: names of the threads

the names are shown in the log file


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@837 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2012-05-19 17:04:33 +00:00
parent 0df088e1e2
commit db9d381a43
6 changed files with 55 additions and 19 deletions

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* Copyright (c) 2011-2012, Tomasz Sowa
* All rights reserved.
*
*/
@@ -40,17 +40,38 @@ sigset_t set;
void ThreadManager::Add(BaseThread * pbase)
void ThreadManager::Add(BaseThread * pbase, const wchar_t * thread_name)
{
thread_tab.push_back(pbase);
ThreadItem item;
item.object = pbase;
item.name = thread_name;
thread_tab.push_back(item);
if( were_started )
Start(thread_tab.size() - 1);
else
log << log4 << "TM: added a thread to the queue, number: " << (thread_tab.size()-1) << logend;
log << log4 << "TM: added a thread to the queue, number: " << (thread_tab.size()-1)
<< ", name: " << thread_name << logend;
}
void ThreadManager::Add(BaseThread & pbase, const wchar_t * thread_name)
{
Add(&pbase, thread_name);
}
void ThreadManager::Add(BaseThread * pbase, const std::wstring & thread_name)
{
Add(pbase, thread_name.c_str());
}
void ThreadManager::Add(BaseThread & pbase, const std::wstring & thread_name)
{
Add(&pbase, thread_name.c_str());
}
void ThreadManager::StartAll()
@@ -70,15 +91,17 @@ void ThreadManager::Start(size_t i)
{
if( i < thread_tab.size() )
{
thread_tab[i]->SetSynchro(synchro);
thread_tab[i].object->SetSynchro(synchro);
if( thread_tab[i]->StartThread() )
if( thread_tab[i].object->StartThread() )
{
log << log4 << "TM: thread " << i << " (" << thread_tab[i]->ThreadId() << ") started" << logend;
log << log4 << "TM: thread " << i << " (" << thread_tab[i].object->ThreadId() << ", name: "
<< thread_tab[i].name << ") started" << logend;
}
else
{
log << log4 << "TM: cannot run a thread, thread number: " << i << logend;
log << log4 << "TM: cannot run a thread, thread number: " << i
<< ", name: " << thread_tab[i].name << logend;
}
}
}
@@ -93,15 +116,18 @@ void ThreadManager::StopAll()
synchro->Lock();
for(size_t i=0 ; i<thread_tab.size() ; ++i)
thread_tab[i]->WakeUpThread();
thread_tab[i].object->WakeUpThread();
synchro->Unlock();
for(size_t i=0 ; i<thread_tab.size() ; ++i)
{
log << log4 << "TM: waiting for thread " << i << " (" << thread_tab[i]->ThreadId() << ")" << logend;
thread_tab[i]->WaitForThread();
log << log4 << "TM: waiting for thread " << i << " (" << thread_tab[i].object->ThreadId()
<< ", name: " << thread_tab[i].name << ")" << logend;
thread_tab[i].object->WaitForThread();
log << log4 << "TM: thread " << i << " terminated" << logend;
}
}