mirror of
https://github.com/mangosfour/server.git
synced 2025-12-18 10:37:01 +00:00
[10865] Make DB code thread-safe. Original patch by Machiavelli and Kero99.
Signed-off-by: Ambal <pogrebniak@gala.net>
This commit is contained in:
parent
9b3535f803
commit
af66b470a8
8 changed files with 53 additions and 26 deletions
|
|
@ -55,27 +55,18 @@ namespace ACE_Based
|
|||
//! Adds an item to the queue.
|
||||
void add(const T& item)
|
||||
{
|
||||
lock();
|
||||
|
||||
//ASSERT(!this->_canceled);
|
||||
// throw Cancellation_Exception();
|
||||
|
||||
ACE_Guard<LockType> g(this->_lock);
|
||||
_queue.push_back(item);
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
//! Gets the next result in the queue, if any.
|
||||
bool next(T& result)
|
||||
{
|
||||
ACE_Guard<LockType> g(this->_lock);
|
||||
ACE_GUARD_RETURN (LockType, g, this->_lock, false);
|
||||
|
||||
if (_queue.empty())
|
||||
return false;
|
||||
|
||||
//ASSERT (!_queue.empty() || !this->_canceled);
|
||||
// throw Cancellation_Exception();
|
||||
|
||||
result = _queue.front();
|
||||
_queue.pop_front();
|
||||
|
||||
|
|
@ -85,7 +76,7 @@ namespace ACE_Based
|
|||
template<class Checker>
|
||||
bool next(T& result, Checker& check)
|
||||
{
|
||||
ACE_Guard<LockType> g(this->_lock);
|
||||
ACE_GUARD_RETURN (LockType, g, this->_lock, false);
|
||||
|
||||
if (_queue.empty())
|
||||
return false;
|
||||
|
|
@ -111,18 +102,14 @@ namespace ACE_Based
|
|||
//! Cancels the queue.
|
||||
void cancel()
|
||||
{
|
||||
lock();
|
||||
|
||||
ACE_Guard<LockType> g(this->_lock);
|
||||
_canceled = true;
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
//! Checks if the queue is cancelled.
|
||||
bool cancelled()
|
||||
{
|
||||
ACE_Guard<LockType> g(this->_lock);
|
||||
|
||||
return _canceled;
|
||||
}
|
||||
|
||||
|
|
@ -137,6 +124,13 @@ namespace ACE_Based
|
|||
{
|
||||
this->_lock.release();
|
||||
}
|
||||
|
||||
///! Checks if we're empty or not with locks held
|
||||
bool empty()
|
||||
{
|
||||
ACE_Guard<LockType> g(this->_lock);
|
||||
return _queue.empty();
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue