summaryrefslogtreecommitdiffstats
path: root/src/Core/ThreadManager.cpp
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-06-18 22:03:02 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-06-18 22:03:02 +0200
commit7234fe326d16d6bf9f4374a09ddc6ef790e6723f (patch)
tree437d4c40eeb1e9b34b369e4b82064a1572c7dac9 /src/Core/ThreadManager.cpp
parentbf561f8226e97f4ace4f04bddf198175e91ee7f0 (diff)
downloadmad-7234fe326d16d6bf9f4374a09ddc6ef790e6723f.tar
mad-7234fe326d16d6bf9f4374a09ddc6ef790e6723f.zip
Globale Variablen durch Application-Klasse ersetzt
Diffstat (limited to 'src/Core/ThreadManager.cpp')
-rw-r--r--src/Core/ThreadManager.cpp23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/Core/ThreadManager.cpp b/src/Core/ThreadManager.cpp
index abc0bc6..c34a734 100644
--- a/src/Core/ThreadManager.cpp
+++ b/src/Core/ThreadManager.cpp
@@ -19,7 +19,7 @@
#include "ThreadManager.h"
-#include "Logger.h"
+#include "Application.h"
#include "LogManager.h"
#include <boost/bind.hpp>
@@ -27,9 +27,6 @@
namespace Mad {
namespace Core {
-ThreadManager ThreadManager::threadManager;
-
-
void ThreadManager::workerFunc() {
while(true) {
boost::unique_lock<boost::mutex> lock(runLock);
@@ -61,7 +58,7 @@ void ThreadManager::workerFunc() {
void ThreadManager::detach() {
if(isThisMainThread()) {
- Logger::log(Logger::CRITICAL, "Tried to detach main thread! This is just WRONG!");
+ application->log(Logger::CRITICAL, "Tried to detach main thread! This is just WRONG!");
return;
}
@@ -91,22 +88,20 @@ void ThreadManager::pushWork(const boost::function0<void> &newWork) {
}
-void ThreadManager::doInit() {
- running = true;
-
+ThreadManager::ThreadManager(Application *application0) : application(application0), running(true) {
threadLock.lock();
- ioWorker.reset(new boost::asio::io_service::work(ioService));
+ ioWorker.reset(new boost::asio::io_service::work(application->getIOService()));
mainThreadId = boost::this_thread::get_id();
workerThread.reset(new boost::thread(&ThreadManager::workerFunc, this));
- loggerThread.reset(new boost::thread(&LogManager::loggerThread, LogManager::get()));
- ioThread.reset(new boost::thread((std::size_t(boost::asio::io_service::*)())&boost::asio::io_service::run, &ioService));
+ loggerThread.reset(new boost::thread(&LogManager::loggerThread, application->getLogManager()));
+ ioThread.reset(new boost::thread((std::size_t(boost::asio::io_service::*)())&boost::asio::io_service::run, &application->getIOService()));
threadLock.unlock();
}
-void ThreadManager::doDeinit() {
+ThreadManager::~ThreadManager() {
if(!isThisMainThread()) {
// TODO Critical error!!!
return;
@@ -131,11 +126,11 @@ void ThreadManager::doDeinit() {
// IO thread is next
ioWorker.reset();
- ioService.stop();
+ application->getIOService().stop();
ioThread->join();
// Finally, the logger thread has to die
- LogManager::get()->stopLoggerThread();
+ application->getLogManager()->stopLoggerThread();
loggerThread->join();
}