diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/LockedQueue.h | 40 |
1 files changed, 36 insertions, 4 deletions
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<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 |