Fix incorrect usage of ACE_Guard
This commit is contained in:
parent
eaeb3ec213
commit
89fbe37e3e
@ -102,7 +102,6 @@ class WorldSocket : protected WorldHandler
|
||||
|
||||
/// Mutex type used for various synchronizations.
|
||||
typedef ACE_Thread_Mutex LockType;
|
||||
typedef ACE_Guard<LockType> GuardType;
|
||||
|
||||
/// Queue for storing packets for which there is no space.
|
||||
typedef ACE_Unbounded_Queue< WorldPacket* > PacketQueueT;
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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<LockType> 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<class Checker>
|
||||
/**
|
||||
* @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<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()
|
||||
{
|
||||
ACE_Guard<LockType> g(this->_lock);
|
||||
ACE_GUARD_RETURN (LockType, g, this->_lock, false);
|
||||
return _queue.empty();
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user