diff options
Diffstat (limited to 'src/Core/ThreadManager.cpp')
-rw-r--r-- | src/Core/ThreadManager.cpp | 23 |
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(); } |