[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: public:
//! Create a LockedQueue. //! Create a LockedQueue.
LockedQueue() : _canceled(false) {} LockedQueue()
: _canceled(false)
{
}
//! Destroy a LockedQueue. //! Destroy a LockedQueue.
virtual ~LockedQueue() { } virtual ~LockedQueue()
{
}
//! Adds an item to the queue. //! Adds an item to the queue.
void add(const T& item) void add(const T& item)
{ {
ACE_Guard<LockType> g(this->_lock); lock();
//ASSERT(!this->_canceled); //ASSERT(!this->_canceled);
// throw Cancellation_Exception(); // throw Cancellation_Exception();
_queue.push_back(item); _queue.push_back(item);
unlock();
} }
//! Gets the next result in the queue, if any. //! Gets the next result in the queue, if any.
@ -75,12 +82,24 @@ namespace ACE_Based
return true; 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. //! Cancels the queue.
void cancel() void cancel()
{ {
ACE_Guard<LockType> g(this->_lock); lock();
_canceled = true; _canceled = true;
unlock();
} }
//! Checks if the queue is cancelled. //! Checks if the queue is cancelled.
@ -90,6 +109,18 @@ namespace ACE_Based
return _canceled; return _canceled;
} }
//! Locks the queue for access.
void lock()
{
this->_lock.acquire();
}
//! Unlocks the queue.
void unlock()
{
this->_lock.release();
}
}; };
} }
#endif #endif

View file

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