diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-05-17 01:34:10 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-05-17 01:34:10 +0200 |
commit | a3e566c4d3631076e29f3651554603184b6351a7 (patch) | |
tree | 71effee59fd4364174f7a845204f946dbc18ff2a /src/Net/ThreadManager.h | |
parent | c8d469cc3de8ef2fb95f7b47355ebf5318a4c22f (diff) | |
download | mad-a3e566c4d3631076e29f3651554603184b6351a7.tar mad-a3e566c4d3631076e29f3651554603184b6351a7.zip |
Gnulib durch boost ersetzt
Diffstat (limited to 'src/Net/ThreadManager.h')
-rw-r--r-- | src/Net/ThreadManager.h | 56 |
1 files changed, 19 insertions, 37 deletions
diff --git a/src/Net/ThreadManager.h b/src/Net/ThreadManager.h index 327ba67..9394329 100644 --- a/src/Net/ThreadManager.h +++ b/src/Net/ThreadManager.h @@ -22,63 +22,47 @@ #include <config.h> -#include "FdManager.h" - #include <Common/Initializable.h> -#include <Common/LogManager.h> #include <queue> #include <set> #include <sigc++/slot.h> -#include "glthread/thread.h" -#include "glthread/lock.h" -#include "glthread/cond.h" +#include <boost/thread/thread.hpp> +#include <boost/thread/condition_variable.hpp> +#include <boost/thread/locks.hpp> namespace Mad { namespace Net { class ThreadManager : public Common::Initializable { private: - gl_thread_t mainThread, workerThread, loggerThread, ioThread; - std::set<gl_thread_t> threads; + boost::thread::id mainThreadId; + boost::thread *workerThread, *loggerThread, *ioThread; + boost::thread_group threads; - gl_lock_t threadLock; + boost::mutex threadLock; - gl_lock_t runLock; + boost::mutex runLock; bool running; - gl_lock_t workLock; - gl_cond_t workCond; + boost::mutex workLock; + boost::condition_variable workCond; std::queue<sigc::slot<void> > work; static ThreadManager threadManager; ThreadManager() {} - static void* workerStart(void*) { - threadManager.workerFunc(); - return 0; - } - - static void* loggerStart(void*) { - Common::LogManager::get()->loggerThread(); - return 0; - } - - static void* ioStart(void*) { - FdManager::get()->ioThread(); - return 0; - } - void workerFunc(); - void threadFinished(gl_thread_t thread) { - gl_lock_lock(threadLock); - threads.erase(thread); - gl_lock_unlock(threadLock); + void threadFinished(boost::thread *thread) { + threadLock.lock(); + threads.remove_thread(thread); + threadLock.unlock(); - gl_thread_join(thread, 0); + thread->join(); + delete thread; } protected: @@ -87,14 +71,12 @@ class ThreadManager : public Common::Initializable { public: bool isThisMainThread() { - return (mainThread == (gl_thread_t)gl_thread_self()); + return (mainThreadId == boost::this_thread::get_id()); } bool isThisWorkerThread() { - gl_lock_lock(threadLock); - bool ret = (workerThread == (gl_thread_t)gl_thread_self()); - gl_lock_unlock(threadLock); - return ret; + boost::lock_guard<boost::mutex> lock(threadLock); + return (workerThread->get_id() == boost::this_thread::get_id()); } void detach(); |