[8861] Add peeking support to LockedQueue.

This commit is contained in:
XTZGZoReX 2009-11-22 23:52:20 +01:00
parent 1f6e574fcc
commit 5b6c4b24d6
2 changed files with 36 additions and 5 deletions

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.
@ -75,12 +82,24 @@ 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.
@ -90,6 +109,18 @@ namespace ACE_Based
return _canceled;
}
//! Locks the queue for access.
void lock()
{
this->_lock.acquire();
}
//! Unlocks the queue.
void unlock()
{
this->_lock.release();
}
};
}
#endif

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "8860"
#define REVISION_NR "8861"
#endif // __REVISION_NR_H__