aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2014-08-12 18:18:52 +0200
committerShauren <shauren.trinity@gmail.com>2014-08-12 18:18:52 +0200
commitbd4edf6e22a3dd60bc68a658de19d18a3b7fd2c3 (patch)
tree6e3a4342f1f127b9c5e82749aa77b84ec6bfe43a
parent9f7075215d0efdb357abf13ed10a10122fe70039 (diff)
Core/Threading: Fixed possible race condition with m_timeOutTime and fixed Thread #1: pthread_cond_{signal,broadcast}: dubious: associated lock is not held by any thread in PCQ
-rw-r--r--src/server/game/Server/WorldSession.h13
-rw-r--r--src/server/shared/Threading/ProducerConsumerQueue.h11
2 files changed, 9 insertions, 15 deletions
diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h
index 98633281e19..2e6a699fc7c 100644
--- a/src/server/game/Server/WorldSession.h
+++ b/src/server/game/Server/WorldSession.h
@@ -373,22 +373,21 @@ class WorldSession
void SetLatency(uint32 latency) { m_latency = latency; }
void ResetClientTimeDelay() { m_clientTimeDelay = 0; }
- std::atomic<time_t> m_timeOutTime;
+ std::atomic<int32> m_timeOutTime;
void UpdateTimeOutTime(uint32 diff)
{
- if (time_t(diff) > m_timeOutTime)
- m_timeOutTime = 0;
- else
- m_timeOutTime -= diff;
+ m_timeOutTime -= int32(diff);
}
+
void ResetTimeOutTime()
{
- m_timeOutTime = sWorld->getIntConfig(CONFIG_SOCKET_TIMEOUTTIME);
+ m_timeOutTime = int32(sWorld->getIntConfig(CONFIG_SOCKET_TIMEOUTTIME));
}
+
bool IsConnectionIdle() const
{
- return (m_timeOutTime <= 0 && !m_inQueue);
+ return m_timeOutTime <= 0 && !m_inQueue;
}
// Recruit-A-Friend Handling
diff --git a/src/server/shared/Threading/ProducerConsumerQueue.h b/src/server/shared/Threading/ProducerConsumerQueue.h
index accb0aebb11..a76b8b0b5c0 100644
--- a/src/server/shared/Threading/ProducerConsumerQueue.h
+++ b/src/server/shared/Threading/ProducerConsumerQueue.h
@@ -39,10 +39,8 @@ public:
void Push(const T& value)
{
- {
- std::lock_guard<std::mutex> lock(_queueLock);
- _queue.push(std::move(value));
- }
+ std::lock_guard<std::mutex> lock(_queueLock);
+ _queue.push(std::move(value));
_condition.notify_one();
}
@@ -72,10 +70,7 @@ public:
{
std::unique_lock<std::mutex> lock(_queueLock);
- while (_queue.empty() && !_shutdown)
- {
- _condition.wait(lock);
- }
+ _condition.wait(lock, [this]() { return !_queue.empty() || _shutdown; });
if (_queue.empty() || _shutdown)
return;