From bd4edf6e22a3dd60bc68a658de19d18a3b7fd2c3 Mon Sep 17 00:00:00 2001 From: Shauren Date: Tue, 12 Aug 2014 18:18:52 +0200 Subject: 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 --- src/server/game/Server/WorldSession.h | 13 ++++++------- src/server/shared/Threading/ProducerConsumerQueue.h | 11 +++-------- 2 files changed, 9 insertions(+), 15 deletions(-) (limited to 'src') 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 m_timeOutTime; + std::atomic 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 lock(_queueLock); - _queue.push(std::move(value)); - } + std::lock_guard lock(_queueLock); + _queue.push(std::move(value)); _condition.notify_one(); } @@ -72,10 +70,7 @@ public: { std::unique_lock lock(_queueLock); - while (_queue.empty() && !_shutdown) - { - _condition.wait(lock); - } + _condition.wait(lock, [this]() { return !_queue.empty() || _shutdown; }); if (_queue.empty() || _shutdown) return; -- cgit v1.2.3