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:
lotodore
2007-03-20 11:56:30 +00:00
parent 53c4af95c8
commit 804c7eaaa2
12 changed files with 160 additions and 55 deletions
+11 -5
View File
@@ -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();
}