aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorn0n4m3 <none@none>2009-12-19 19:52:23 +0100
committern0n4m3 <none@none>2009-12-19 19:52:23 +0100
commitacc95b66c922863ecb77a02154ff2d04db4089e7 (patch)
treeba2efe37805984d4e248b7bcd176669e1fada330
parent2a0afbf2fca5d125de11e81d03d5b04ea02061c1 (diff)
Add peeking support to LockedQueue. by XTZGZoReX
--HG-- branch : trunk
-rw-r--r--src/shared/LockedQueue.h40
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