Fixed design problem: Thread objects can now be created in any context.
Sender thread output queue is now limited. Server thread now terminates correctly. Now cloning packets when sending them to multiple recipients. Fixed one thread issue - GameStart still needs to be made thread safe.
This commit is contained in:
1 parent
53c4af95c8
commit
804c7eaaa2
12 files changed
+160
-55
No files matched your search
@@ -47,7 +47,6 @@ private:
|
||||
};
|
||||
|
||||
Thread::Thread()
|
||||
: m_userReqTerminateLock(m_shouldTerminateMutex), m_threadStartBarrier(2)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -58,13 +57,18 @@ Thread::~Thread()
|
||||
void
|
||||
Thread::Run()
|
||||
{
|
||||
// Create the boost thread object.
|
||||
boost::mutex::scoped_lock threadLock(m_threadObjMutex);
|
||||
|
||||
// Create the boost thread object.
|
||||
if (!m_threadObj.get())
|
||||
{
|
||||
// Initialise data structures within the context of the thread
|
||||
// who runs/terminates this thread.
|
||||
m_userReqTerminateLock.reset(new boost::timed_mutex::scoped_try_lock(m_shouldTerminateMutex));
|
||||
m_threadStartBarrier.reset(new boost::barrier(2));
|
||||
|
||||
m_threadObj.reset(new boost::thread(ThreadStarter(*this)));
|
||||
m_threadStartBarrier.wait();
|
||||
m_threadStartBarrier->wait();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +76,8 @@ void
|
||||
Thread::SignalTermination()
|
||||
{
|
||||
// Unlock the shouldTerminateMutex.
|
||||
m_userReqTerminateLock.unlock();
|
||||
if (m_userReqTerminateLock.get()) // cannot signal before calling Run
|
||||
m_userReqTerminateLock->unlock();
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -118,7 +123,8 @@ void
|
||||
Thread::MainWrapper()
|
||||
{
|
||||
boost::timed_mutex::scoped_lock lock(m_isTerminatedMutex);
|
||||
m_threadStartBarrier.wait();
|
||||
assert(m_threadStartBarrier.get());
|
||||
m_threadStartBarrier->wait();
|
||||
this->Main();
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -72,13 +72,13 @@ private:
|
||||
|
||||
// Flag specifying whether the thread should be terminated.
|
||||
mutable boost::timed_mutex m_shouldTerminateMutex;
|
||||
mutable boost::timed_mutex::scoped_try_lock m_userReqTerminateLock;
|
||||
mutable boost::shared_ptr<boost::timed_mutex::scoped_try_lock> m_userReqTerminateLock;
|
||||
|
||||
// The boost thread object.
|
||||
boost::shared_ptr<boost::thread> m_threadObj;
|
||||
mutable boost::mutex m_threadObjMutex;
|
||||
|
||||
boost::barrier m_threadStartBarrier;
|
||||
mutable boost::shared_ptr<boost::barrier> m_threadStartBarrier;
|
||||
|
||||
friend class ThreadStarter;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user