summaryrefslogtreecommitdiffstats
path: root/src/Net/ThreadManager.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Net/ThreadManager.h')
-rw-r--r--src/Net/ThreadManager.h25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/Net/ThreadManager.h b/src/Net/ThreadManager.h
index 2c57747..b8c4bec 100644
--- a/src/Net/ThreadManager.h
+++ b/src/Net/ThreadManager.h
@@ -25,7 +25,7 @@
#include <Common/Initializable.h>
#include <queue>
-#include <set>
+#include <map>
#include <boost/asio.hpp>
@@ -39,8 +39,8 @@ namespace Net {
class ThreadManager : public Common::Initializable {
private:
boost::thread::id mainThreadId;
- boost::thread *workerThread, *loggerThread, *ioThread;
- boost::thread_group threads;
+ boost::shared_ptr<boost::thread> workerThread, loggerThread, ioThread;
+ std::map<boost::thread::id, boost::shared_ptr<boost::thread> > threads;
boost::mutex threadLock;
@@ -60,13 +60,22 @@ class ThreadManager : public Common::Initializable {
void workerFunc();
void ioFunc();
- void threadFinished(boost::thread *thread) {
- threadLock.lock();
- threads.remove_thread(thread);
- threadLock.unlock();
+ void threadFinished(boost::thread::id threadId) {
+ boost::shared_ptr<boost::thread> thread;
+
+ {
+ boost::lock_guard<boost::mutex> lock(threadLock);
+
+ std::map<boost::thread::id, boost::shared_ptr<boost::thread> >::iterator it = threads.find(threadId);
+
+ if(it == threads.end())
+ return;
+
+ thread = it->second;
+ threads.erase(it);
+ }
thread->join();
- delete thread;
}
protected: