aboutsummaryrefslogtreecommitdiff
path: root/dep/include/zthread/MonitoredQueue.h
diff options
context:
space:
mode:
Diffstat (limited to 'dep/include/zthread/MonitoredQueue.h')
-rw-r--r--dep/include/zthread/MonitoredQueue.h86
1 files changed, 43 insertions, 43 deletions
diff --git a/dep/include/zthread/MonitoredQueue.h b/dep/include/zthread/MonitoredQueue.h
index 8578fe62b96..2122b7f7a28 100644
--- a/dep/include/zthread/MonitoredQueue.h
+++ b/dep/include/zthread/MonitoredQueue.h
@@ -37,12 +37,12 @@ namespace ZThread {
* @date <2003-07-16T20:23:28-0400>
* @version 2.3.0
*
- * A MonitoredQueue is a Queue implementation that provides serialized access to the
- * items added to it.
+ * A MonitoredQueue is a Queue implementation that provides serialized access to the
+ * items added to it.
*
- * - Threads calling the empty() methods will be blocked until the BoundedQueue becomes empty.
+ * - Threads calling the empty() methods will be blocked until the BoundedQueue becomes empty.
* - Threads calling the next() methods will be blocked until the BoundedQueue has a value to
- * return.
+ * return.
*
* @see Queue
*/
@@ -67,17 +67,17 @@ namespace ZThread {
public:
//! Create a new MonitoredQueue
- MonitoredQueue()
+ MonitoredQueue()
: _notEmpty(_lock), _isEmpty(_lock), _canceled(false) {}
//! Destroy a MonitoredQueue, delete remaining items
virtual ~MonitoredQueue() { }
/**
- * Add a value to this Queue.
+ * Add a value to this Queue.
*
* @param item value to be added to the Queue
- *
+ *
* @exception Cancellation_Exception thrown if this Queue has been canceled.
* @exception Interrupted_Exception thrown if the thread was interrupted while waiting
* to add a value
@@ -90,7 +90,7 @@ namespace ZThread {
virtual void add(const T& item) {
Guard<LockType> g(_lock);
-
+
// Allow no further additions in the canceled state
if(_canceled)
throw Cancellation_Exception();
@@ -102,14 +102,14 @@ namespace ZThread {
}
/**
- * Add a value to this Queue.
+ * Add a value to this Queue.
*
* @param item value to be added to the Queue
* @param timeout maximum amount of time (milliseconds) this method may block
* the calling thread.
*
- * @return
- * - <em>true</em> if a copy of <i>item</i> can be added before <i>timeout</i>
+ * @return
+ * - <em>true</em> if a copy of <i>item</i> can be added before <i>timeout</i>
* milliseconds elapse.
* - <em>false</em> otherwise.
*
@@ -123,32 +123,32 @@ namespace ZThread {
* @see Queue::add(const T& item, unsigned long timeout)
*/
virtual bool add(const T& item, unsigned long timeout) {
-
+
try {
Guard<LockType> g(_lock, timeout);
-
+
if(_canceled)
throw Cancellation_Exception();
-
+
_queue.push_back(item);
_notEmpty.signal();
} catch(Timeout_Exception&) { return false; }
-
- return true;
+
+ return true;
}
/**
* Retrieve and remove a value from this Queue.
*
- * If invoked when there are no values present to return then the calling thread
+ * If invoked when there are no values present to return then the calling thread
* will be blocked until a value arrives in the Queue.
*
* @return <em>T</em> next available value
- *
+ *
* @exception Cancellation_Exception thrown if this Queue has been canceled.
* @exception Interrupted_Exception thrown if the thread was interrupted while waiting
* to retrieve a value
@@ -157,15 +157,15 @@ namespace ZThread {
* @post The value returned will have been removed from the Queue.
*/
virtual T next() {
-
+
Guard<LockType> g(_lock);
-
- while (_queue.empty() && !_canceled)
+
+ while (_queue.empty() && !_canceled)
_notEmpty.wait();
-
+
if(_queue.empty()) // Queue canceled
- throw Cancellation_Exception();
-
+ throw Cancellation_Exception();
+
T item = _queue.front();
_queue.pop_front();
@@ -179,14 +179,14 @@ namespace ZThread {
/**
* Retrieve and remove a value from this Queue.
*
- * If invoked when there are no values present to return then the calling thread
+ * If invoked when there are no values present to return then the calling thread
* will be blocked until a value arrives in the Queue.
*
* @param timeout maximum amount of time (milliseconds) this method may block
* the calling thread.
*
* @return <em>T</em> next available value
- *
+ *
* @exception Cancellation_Exception thrown if this Queue has been canceled.
* @exception Timeout_Exception thrown if the timeout expires before a value
* can be retrieved.
@@ -195,16 +195,16 @@ namespace ZThread {
* @post The value returned will have been removed from the Queue.
*/
virtual T next(unsigned long timeout) {
-
+
Guard<LockType> g(_lock, timeout);
-
+
while(_queue.empty() && !_canceled) {
if(!_notEmpty.wait(timeout))
throw Timeout_Exception();
}
if( _queue.empty()) // Queue canceled
- throw Cancellation_Exception();
+ throw Cancellation_Exception();
T item = _queue.front();
_queue.pop_front();
@@ -218,10 +218,10 @@ namespace ZThread {
/**
- * Cancel this queue.
- *
+ * Cancel this queue.
+ *
* @post Any threads blocked by a next() function will throw a Cancellation_Exception.
- *
+ *
* @see Queue::cancel()
*/
virtual void cancel() {
@@ -237,11 +237,11 @@ namespace ZThread {
* @see Queue::isCanceled()
*/
virtual bool isCanceled() {
-
+
// Faster check since the queue will not become un-canceled
if(_canceled)
return true;
-
+
Guard<LockType> g(_lock);
return _canceled;
@@ -272,10 +272,10 @@ namespace ZThread {
/**
* Test whether any values are available in this Queue.
*
- * The calling thread is blocked until there are no values present
+ * The calling thread is blocked until there are no values present
* in the Queue.
- *
- * @return
+ *
+ * @return
* - <em>true</em> if there are no values available.
* - <em>false</em> if there <i>are</i> values available.
*
@@ -287,7 +287,7 @@ namespace ZThread {
while(!_queue.empty()) // Wait for an empty signal
_isEmpty.wait();
-
+
return true;
}
@@ -295,13 +295,13 @@ namespace ZThread {
/**
* Test whether any values are available in this Queue.
*
- * The calling thread is blocked until there are no values present
+ * The calling thread is blocked until there are no values present
* in the Queue.
- *
+ *
* @param timeout maximum amount of time (milliseconds) this method may block
* the calling thread.
*
- * @return
+ * @return
* - <em>true</em> if there are no values available.
* - <em>false</em> if there <i>are</i> values available.
*
@@ -311,12 +311,12 @@ namespace ZThread {
* @see Queue::empty()
*/
virtual bool empty(unsigned long timeout) {
-
+
Guard<LockType> g(_lock, timeout);
while(!_queue.empty()) // Wait for an empty signal
_isEmpty.wait(timeout);
-
+
return true;
}