start working on 0.7.x branch
- added FileLog which stores content to the file log - now Log is only a wrapper - it puts messages to the local buffer and when logsave is used then the buffer is put to FileLog - new base classes: WinixBase (Log, Config*, Synchro*) WinixModel : public WinixBase (morm::ModelConnector*, Plugin*) WinixSystem : public WinixModel (System*) WinixRequest : public WinixSystem (SLog, Cur*) - singletons: log, slog, plugin are depracated - now references to them are in base classses (WinixBase, WinixModel) - DbBase, DbConn and Db are depracated - now we are using Morm project (in WinixModel there is a model_connector pointer) each thread will have its own ModelConnector git-svn-id: svn://ttmath.org/publicrep/winix/branches/0.7.x@1146 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||
* Copyright (c) 2011-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -49,10 +49,10 @@ ThreadManager::ThreadManager()
|
||||
}
|
||||
|
||||
|
||||
void ThreadManager::SetSynchro(Synchro * psynchro)
|
||||
{
|
||||
synchro = psynchro;
|
||||
}
|
||||
//void ThreadManager::SetSynchro(Synchro * psynchro)
|
||||
//{
|
||||
// synchro = psynchro;
|
||||
//}
|
||||
|
||||
|
||||
void ThreadManager::Init()
|
||||
@@ -70,20 +70,37 @@ sigset_t set;
|
||||
|
||||
|
||||
|
||||
|
||||
void ThreadManager::Add(BaseThread * pbase, const wchar_t * thread_name)
|
||||
{
|
||||
ThreadItem item;
|
||||
|
||||
item.object = pbase;
|
||||
item.name = thread_name;
|
||||
|
||||
thread_tab.push_back(item);
|
||||
thread_tab.back().thread_item_data = new ThreadItemData();
|
||||
thread_tab.back().object->set_dependency(this);
|
||||
|
||||
// the logger buffer and model_connector are different
|
||||
ThreadItemData & data = *thread_tab.back().thread_item_data;
|
||||
thread_tab.back().object->set_log_buffer(&data.log_buffer);
|
||||
|
||||
//data.postgresql_connector.set_logger(logger);
|
||||
data.postgresql_connector.set_conn_param(config->db_database, config->db_user, config->db_pass);
|
||||
data.postgresql_connector.wait_for_connection();
|
||||
data.model_connector.set_db_connector(data.postgresql_connector);
|
||||
data.model_connector.set_flat_connector(data.json_connector);
|
||||
thread_tab.back().object->set_model_connector(&data.model_connector);
|
||||
|
||||
if( were_started )
|
||||
Start(thread_tab.size() - 1);
|
||||
{
|
||||
Start(thread_tab.size() - 1, &thread_tab.back());
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log4 << "TM: added a thread to the queue, number: " << (thread_tab.size()-1)
|
||||
<< ", name: " << thread_name << logend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,8 +126,13 @@ void ThreadManager::StartAll()
|
||||
{
|
||||
synchro->Lock();
|
||||
|
||||
for(size_t i=0 ; i<thread_tab.size() ; ++i)
|
||||
Start(i);
|
||||
int id = 0;
|
||||
|
||||
for(ThreadItem & item : thread_tab)
|
||||
{
|
||||
Start(id, &item);
|
||||
id += 1;
|
||||
}
|
||||
|
||||
synchro->Unlock();
|
||||
|
||||
@@ -118,22 +140,18 @@ void ThreadManager::StartAll()
|
||||
}
|
||||
|
||||
|
||||
void ThreadManager::Start(size_t i)
|
||||
void ThreadManager::Start(int id, ThreadItem * item)
|
||||
{
|
||||
if( i < thread_tab.size() )
|
||||
{
|
||||
thread_tab[i].object->SetSynchro(synchro);
|
||||
item->object->SetSynchro(synchro);
|
||||
|
||||
if( thread_tab[i].object->StartThread() )
|
||||
{
|
||||
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
|
||||
<< ", name: " << thread_tab[i].name << logend;
|
||||
}
|
||||
if( item->object->StartThread() )
|
||||
{
|
||||
log << log4 << "TM: thread " << id << " (" << item->object->ThreadId() << ", name: "
|
||||
<< item->name << ") started" << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log4 << "TM: cannot run a thread " << id << ", name: " << item->name << logend;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,21 +164,29 @@ void ThreadManager::StopAll()
|
||||
// WakeUpThread() should be used with Lock/Unlock
|
||||
synchro->Lock();
|
||||
|
||||
for(size_t i=0 ; i<thread_tab.size() ; ++i)
|
||||
thread_tab[i].object->WakeUpThread();
|
||||
for(ThreadItem & item : thread_tab)
|
||||
{
|
||||
item.object->WakeUpThread();
|
||||
}
|
||||
|
||||
synchro->Unlock();
|
||||
|
||||
|
||||
for(size_t i=0 ; i<thread_tab.size() ; ++i)
|
||||
int id = 0;
|
||||
|
||||
for(ThreadItem & item : thread_tab)
|
||||
{
|
||||
log << log4 << "TM: waiting for thread " << i << " (" << thread_tab[i].object->ThreadId()
|
||||
<< ", name: " << thread_tab[i].name << ")" << logend;
|
||||
log << log4 << "TM: waiting for thread " << id << " (" << item.object->ThreadId()
|
||||
<< ", name: " << item.name << ")" << logend;
|
||||
|
||||
thread_tab[i].object->WaitForThread();
|
||||
item.object->WaitForThread();
|
||||
log << log4 << "TM: thread " << id << " terminated" << logend;
|
||||
|
||||
log << log4 << "TM: thread " << i << " terminated" << logend;
|
||||
delete item.thread_item_data;
|
||||
id += 1;
|
||||
}
|
||||
|
||||
thread_tab.clear();
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user