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:
parent
0df088e1e2
commit
db9d381a43
|
@ -1305,7 +1305,7 @@ void App::StartThreads()
|
||||||
// special thread only for signals
|
// special thread only for signals
|
||||||
pthread_create(&signal_thread, 0, SpecialThreadForSignals, this);
|
pthread_create(&signal_thread, 0, SpecialThreadForSignals, this);
|
||||||
|
|
||||||
system.thread_manager.Add(&session_manager);
|
system.thread_manager.Add(&session_manager, L"session_manager");
|
||||||
system.thread_manager.StartAll();
|
system.thread_manager.StartAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,13 +87,13 @@ void System::Init()
|
||||||
image.SetDb(db);
|
image.SetDb(db);
|
||||||
image.SetConfig(config);
|
image.SetConfig(config);
|
||||||
image.SetSystem(this);
|
image.SetSystem(this);
|
||||||
thread_manager.Add(&image);
|
thread_manager.Add(&image, L"image");
|
||||||
|
|
||||||
crypt.SetConfig(config);
|
crypt.SetConfig(config);
|
||||||
|
|
||||||
// SetSynchro will be called by ThreadManager itself
|
// SetSynchro will be called by ThreadManager itself
|
||||||
// job.ReadFromFile();
|
// job.ReadFromFile();
|
||||||
thread_manager.Add(&job);
|
thread_manager.Add(&job, L"job");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* This file is a part of Winix
|
* This file is a part of Winix
|
||||||
* and is not publicly distributed
|
* and is not publicly distributed
|
||||||
*
|
*
|
||||||
* Copyright (c) 2011, Tomasz Sowa
|
* Copyright (c) 2011-2012, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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 )
|
if( were_started )
|
||||||
Start(thread_tab.size() - 1);
|
Start(thread_tab.size() - 1);
|
||||||
else
|
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()
|
void ThreadManager::StartAll()
|
||||||
|
@ -70,15 +91,17 @@ void ThreadManager::Start(size_t i)
|
||||||
{
|
{
|
||||||
if( i < thread_tab.size() )
|
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
|
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();
|
synchro->Lock();
|
||||||
|
|
||||||
for(size_t i=0 ; i<thread_tab.size() ; ++i)
|
for(size_t i=0 ; i<thread_tab.size() ; ++i)
|
||||||
thread_tab[i]->WakeUpThread();
|
thread_tab[i].object->WakeUpThread();
|
||||||
|
|
||||||
synchro->Unlock();
|
synchro->Unlock();
|
||||||
|
|
||||||
|
|
||||||
for(size_t i=0 ; i<thread_tab.size() ; ++i)
|
for(size_t i=0 ; i<thread_tab.size() ; ++i)
|
||||||
{
|
{
|
||||||
log << log4 << "TM: waiting for thread " << i << " (" << thread_tab[i]->ThreadId() << ")" << logend;
|
log << log4 << "TM: waiting for thread " << i << " (" << thread_tab[i].object->ThreadId()
|
||||||
thread_tab[i]->WaitForThread();
|
<< ", name: " << thread_tab[i].name << ")" << logend;
|
||||||
|
|
||||||
|
thread_tab[i].object->WaitForThread();
|
||||||
|
|
||||||
log << log4 << "TM: thread " << i << " terminated" << logend;
|
log << log4 << "TM: thread " << i << " terminated" << logend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* This file is a part of Winix
|
* This file is a part of Winix
|
||||||
* and is not publicly distributed
|
* and is not publicly distributed
|
||||||
*
|
*
|
||||||
* Copyright (c) 2011, Tomasz Sowa
|
* Copyright (c) 2011-2012, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -10,6 +10,7 @@
|
||||||
#ifndef headerfile_winix_core_threadmanager
|
#ifndef headerfile_winix_core_threadmanager
|
||||||
#define headerfile_winix_core_threadmanager
|
#define headerfile_winix_core_threadmanager
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "basethread.h"
|
#include "basethread.h"
|
||||||
#include "synchro.h"
|
#include "synchro.h"
|
||||||
|
@ -31,7 +32,10 @@ public:
|
||||||
// adding a new thread to the queue
|
// adding a new thread to the queue
|
||||||
// the thread will be running only if we call StartAll() before
|
// the thread will be running only if we call StartAll() before
|
||||||
// otherwise the thread will be waiting for StartAll()
|
// otherwise the thread will be waiting for StartAll()
|
||||||
void Add(BaseThread * pbase);
|
void Add(BaseThread * pbase, const wchar_t * thread_name);
|
||||||
|
void Add(BaseThread & pbase, const wchar_t * thread_name);
|
||||||
|
void Add(BaseThread * pbase, const std::wstring & thread_name);
|
||||||
|
void Add(BaseThread & pbase, const std::wstring & thread_name);
|
||||||
|
|
||||||
// starting all threads
|
// starting all threads
|
||||||
void StartAll();
|
void StartAll();
|
||||||
|
@ -42,8 +46,14 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
struct ThreadItem
|
||||||
|
{
|
||||||
|
BaseThread * object;
|
||||||
|
std::wstring name;
|
||||||
|
};
|
||||||
|
|
||||||
Synchro * synchro;
|
Synchro * synchro;
|
||||||
typedef std::vector<BaseThread*> ThreadTab;
|
typedef std::vector<ThreadItem> ThreadTab;
|
||||||
ThreadTab thread_tab;
|
ThreadTab thread_tab;
|
||||||
bool were_started;
|
bool were_started;
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ void Notify::Init()
|
||||||
notify_thread.SetUsers(users);
|
notify_thread.SetUsers(users);
|
||||||
notify_thread.SetNotifyPool(¬ify_pool);
|
notify_thread.SetNotifyPool(¬ify_pool);
|
||||||
notify_thread.SetPatterns(&patterns);
|
notify_thread.SetPatterns(&patterns);
|
||||||
thread_manager->Add(¬ify_thread);
|
thread_manager->Add(¬ify_thread, L"notifications");
|
||||||
|
|
||||||
patterns.SetUTF8(config->utf8);
|
patterns.SetUTF8(config->utf8);
|
||||||
patterns.SetDirectories(config->txt_templates_dir, config->txt_templates_dir_default);
|
patterns.SetDirectories(config->txt_templates_dir, config->txt_templates_dir_default);
|
||||||
|
|
|
@ -53,7 +53,7 @@ void InitPlugin(PluginInfo & info)
|
||||||
export_thread.SetUTF8(info.config->utf8);
|
export_thread.SetUTF8(info.config->utf8);
|
||||||
export_thread.SetBaseUrl(info.config->base_url);
|
export_thread.SetBaseUrl(info.config->base_url);
|
||||||
|
|
||||||
info.system->thread_manager.Add(&export_thread);
|
info.system->thread_manager.Add(&export_thread, L"export");
|
||||||
|
|
||||||
export_info.ReadExportDirs();
|
export_info.ReadExportDirs();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue