Add peeking support to LockedQueue. by XTZGZoReX

--HG--
branch : trunk
This commit is contained in:
n0n4m3
2009-12-19 19:52:23 +01:00
parent 2a0afbf2fc
commit acc95b66c9

View File

@@ -42,20 +42,27 @@ namespace ACE_Based
public:
//! Create a LockedQueue.
LockedQueue() : _canceled(false) {}
LockedQueue()
: _canceled(false)
{
}
//! Destroy a LockedQueue.
virtual ~LockedQueue() { }
virtual ~LockedQueue()
{
}
//! Adds an item to the queue.
void add(const T& item)
{
ACE_Guard<LockType> g(this->_lock);
lock();
//ASSERT(!this->_canceled);
// throw Cancellation_Exception();
_queue.push_back(item);
unlock();
}
//! Gets the next result in the queue, if any.
@@ -74,12 +81,25 @@ namespace ACE_Based
return true;
}
//! Peeks at the top of the queue. Remember to unlock after use.
T& peek()
{
lock();
T& result = _queue.front();
return result;
}
//! Cancels the queue.
void cancel()
{
ACE_Guard<LockType> g(this->_lock);
lock();
_canceled = true;
unlock();
}
//! Checks if the queue is cancelled.
@@ -88,6 +108,18 @@ namespace ACE_Based
ACE_Guard<LockType> g(this->_lock);
return _canceled;
}
//! Locks the queue for access.
void lock()
{
this->_lock.acquire();
}
//! Unlocks the queue.
void unlock()
{
this->_lock.release();
}
};
}
#endif