From acc95b66c922863ecb77a02154ff2d04db4089e7 Mon Sep 17 00:00:00 2001 From: n0n4m3 Date: Sat, 19 Dec 2009 19:52:23 +0100 Subject: Add peeking support to LockedQueue. by XTZGZoReX --HG-- branch : trunk --- src/shared/LockedQueue.h | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/shared/LockedQueue.h b/src/shared/LockedQueue.h index 6543487da81..c07ffcacb02 100644 --- a/src/shared/LockedQueue.h +++ b/src/shared/LockedQueue.h @@ -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 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 g(this->_lock); + lock(); _canceled = true; + + unlock(); } //! Checks if the queue is cancelled. @@ -88,6 +108,18 @@ namespace ACE_Based ACE_Guard g(this->_lock); return _canceled; } + + //! Locks the queue for access. + void lock() + { + this->_lock.acquire(); + } + + //! Unlocks the queue. + void unlock() + { + this->_lock.release(); + } }; } #endif -- cgit v1.2.3