From 89fbe37e3e3fbd480546df9cb7e04131f282b46f Mon Sep 17 00:00:00 2001 From: H0zen Date: Thu, 3 May 2018 09:39:08 +0300 Subject: [PATCH] Fix incorrect usage of ACE_Guard --- src/game/Server/WorldSocket.h | 1 - src/shared/Database/Database.cpp | 16 +++-- src/shared/LockedQueue/LockedQueue.h | 95 +--------------------------- 3 files changed, 12 insertions(+), 100 deletions(-) diff --git a/src/game/Server/WorldSocket.h b/src/game/Server/WorldSocket.h index 5cbf8c16..a945f153 100644 --- a/src/game/Server/WorldSocket.h +++ b/src/game/Server/WorldSocket.h @@ -102,7 +102,6 @@ class WorldSocket : protected WorldHandler /// Mutex type used for various synchronizations. typedef ACE_Thread_Mutex LockType; - typedef ACE_Guard GuardType; /// Queue for storing packets for which there is no space. typedef ACE_Unbounded_Queue< WorldPacket* > PacketQueueT; diff --git a/src/shared/Database/Database.cpp b/src/shared/Database/Database.cpp index ce76009c..9c008452 100644 --- a/src/shared/Database/Database.cpp +++ b/src/shared/Database/Database.cpp @@ -596,6 +596,7 @@ SqlStatement Database::CreateStatement(SqlStatementID& index, const char* fmt) int nParams = std::count(szFmt.begin(), szFmt.end(), '?'); // find existing or add a new record in registry LOCK_GUARD _guard(m_stmtGuard); + MANGOS_ASSERT(_guard.locked()); PreparedStmtRegistry::const_iterator iter = m_stmtRegistry.find(szFmt); if (iter == m_stmtRegistry.end()) { @@ -614,18 +615,19 @@ SqlStatement Database::CreateStatement(SqlStatementID& index, const char* fmt) std::string Database::GetStmtString(const int stmtId) const { - LOCK_GUARD _guard(m_stmtGuard); - if (stmtId == -1 || stmtId > m_iStmtIndex) { return std::string(); } - PreparedStmtRegistry::const_iterator iter_last = m_stmtRegistry.end(); - for (PreparedStmtRegistry::const_iterator iter = m_stmtRegistry.begin(); iter != iter_last; ++iter) + LOCK_GUARD _guard(m_stmtGuard); + if (_guard.locked()) { - if (iter->second == stmtId) - { return iter->first; } + PreparedStmtRegistry::const_iterator iter_last = m_stmtRegistry.end(); + for (PreparedStmtRegistry::const_iterator iter = m_stmtRegistry.begin(); iter != iter_last; ++iter) + { + if (iter->second == stmtId) + { return iter->first; } + } } - return std::string(); } diff --git a/src/shared/LockedQueue/LockedQueue.h b/src/shared/LockedQueue/LockedQueue.h index b02a778c..32f1c3d6 100644 --- a/src/shared/LockedQueue/LockedQueue.h +++ b/src/shared/LockedQueue/LockedQueue.h @@ -41,47 +41,23 @@ namespace ACE_Based class LockedQueue { LockType _lock; /**< Lock access to the queue. */ - StorageType _queue; /**< Storage backing the queue. */ - /*volatile*/ bool _canceled; /**< Cancellation flag. */ - public: - - /** - * @brief Create a LockedQueue. - * - */ - LockedQueue() - : _canceled(false) + LockedQueue(): _lock(), _queue() { } - /** - * @brief Destroy a LockedQueue. - * - */ virtual ~LockedQueue() { } - /** - * @brief Adds an item to the queue. - * - * @param item - */ void add(const T& item) { - ACE_Guard g(this->_lock); + ACE_GUARD (LockType, g, this->_lock); _queue.push_back(item); } - /** - * @brief Gets the next result in the queue, if any. - * - * @param result - * @return bool - */ bool next(T& result) { ACE_GUARD_RETURN(LockType, g, this->_lock, false); @@ -96,13 +72,6 @@ namespace ACE_Based } template - /** - * @brief - * - * @param result - * @param check - * @return bool - */ bool next(T& result, Checker& check) { ACE_GUARD_RETURN(LockType, g, this->_lock, false); @@ -118,67 +87,9 @@ namespace ACE_Based return true; } - /** - * @brief Peeks at the top of the queue. Remember to unlock after use. - * - * @return T - */ - T& peek() - { - lock(); - - T& result = _queue.front(); - - return result; - } - - /** - * @brief Cancels the queue. - * - */ - void cancel() - { - ACE_Guard g(this->_lock); - _canceled = true; - } - - /** - * @brief Checks if the queue is cancelled. - * - * @return bool - */ - bool cancelled() - { - ACE_Guard g(this->_lock); - return _canceled; - } - - /** - * @brief Locks the queue for access. - * - */ - void lock() - { - this->_lock.acquire(); - } - - /** - * @brief Unlocks the queue. - * - */ - void unlock() - { - this->_lock.release(); - } - - /** - * @brief Checks if we're empty or not with locks held - * - * @return bool - */ bool empty() { - ACE_Guard g(this->_lock); + ACE_GUARD_RETURN (LockType, g, this->_lock, false); return _queue.empty(); } };