Fix incorrect usage of ACE_Guard

This commit is contained in:
H0zen 2018-05-03 09:39:08 +03:00
parent eaeb3ec213
commit 89fbe37e3e
3 changed files with 12 additions and 100 deletions

View File

@ -102,7 +102,6 @@ class WorldSocket : protected WorldHandler
/// Mutex type used for various synchronizations. /// Mutex type used for various synchronizations.
typedef ACE_Thread_Mutex LockType; typedef ACE_Thread_Mutex LockType;
typedef ACE_Guard<LockType> GuardType;
/// Queue for storing packets for which there is no space. /// Queue for storing packets for which there is no space.
typedef ACE_Unbounded_Queue< WorldPacket* > PacketQueueT; typedef ACE_Unbounded_Queue< WorldPacket* > PacketQueueT;

View File

@ -596,6 +596,7 @@ SqlStatement Database::CreateStatement(SqlStatementID& index, const char* fmt)
int nParams = std::count(szFmt.begin(), szFmt.end(), '?'); int nParams = std::count(szFmt.begin(), szFmt.end(), '?');
// find existing or add a new record in registry // find existing or add a new record in registry
LOCK_GUARD _guard(m_stmtGuard); LOCK_GUARD _guard(m_stmtGuard);
MANGOS_ASSERT(_guard.locked());
PreparedStmtRegistry::const_iterator iter = m_stmtRegistry.find(szFmt); PreparedStmtRegistry::const_iterator iter = m_stmtRegistry.find(szFmt);
if (iter == m_stmtRegistry.end()) 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 std::string Database::GetStmtString(const int stmtId) const
{ {
LOCK_GUARD _guard(m_stmtGuard);
if (stmtId == -1 || stmtId > m_iStmtIndex) if (stmtId == -1 || stmtId > m_iStmtIndex)
{ return std::string(); } { return std::string(); }
PreparedStmtRegistry::const_iterator iter_last = m_stmtRegistry.end(); LOCK_GUARD _guard(m_stmtGuard);
for (PreparedStmtRegistry::const_iterator iter = m_stmtRegistry.begin(); iter != iter_last; ++iter) if (_guard.locked())
{ {
if (iter->second == stmtId) PreparedStmtRegistry::const_iterator iter_last = m_stmtRegistry.end();
{ return iter->first; } for (PreparedStmtRegistry::const_iterator iter = m_stmtRegistry.begin(); iter != iter_last; ++iter)
{
if (iter->second == stmtId)
{ return iter->first; }
}
} }
return std::string(); return std::string();
} }

View File

@ -41,47 +41,23 @@ namespace ACE_Based
class LockedQueue class LockedQueue
{ {
LockType _lock; /**< Lock access to the queue. */ LockType _lock; /**< Lock access to the queue. */
StorageType _queue; /**< Storage backing the queue. */ StorageType _queue; /**< Storage backing the queue. */
/*volatile*/ bool _canceled; /**< Cancellation flag. */
public: public:
LockedQueue(): _lock(), _queue()
/**
* @brief Create a LockedQueue.
*
*/
LockedQueue()
: _canceled(false)
{ {
} }
/**
* @brief Destroy a LockedQueue.
*
*/
virtual ~LockedQueue() virtual ~LockedQueue()
{ {
} }
/**
* @brief Adds an item to the queue.
*
* @param item
*/
void add(const T& item) void add(const T& item)
{ {
ACE_Guard<LockType> g(this->_lock); ACE_GUARD (LockType, g, this->_lock);
_queue.push_back(item); _queue.push_back(item);
} }
/**
* @brief Gets the next result in the queue, if any.
*
* @param result
* @return bool
*/
bool next(T& result) bool next(T& result)
{ {
ACE_GUARD_RETURN(LockType, g, this->_lock, false); ACE_GUARD_RETURN(LockType, g, this->_lock, false);
@ -96,13 +72,6 @@ namespace ACE_Based
} }
template<class Checker> template<class Checker>
/**
* @brief
*
* @param result
* @param check
* @return bool
*/
bool next(T& result, Checker& check) bool next(T& result, Checker& check)
{ {
ACE_GUARD_RETURN(LockType, g, this->_lock, false); ACE_GUARD_RETURN(LockType, g, this->_lock, false);
@ -118,67 +87,9 @@ namespace ACE_Based
return true; 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<LockType> g(this->_lock);
_canceled = true;
}
/**
* @brief Checks if the queue is cancelled.
*
* @return bool
*/
bool cancelled()
{
ACE_Guard<LockType> 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() bool empty()
{ {
ACE_Guard<LockType> g(this->_lock); ACE_GUARD_RETURN (LockType, g, this->_lock, false);
return _queue.empty(); return _queue.empty();
} }
}; };