aboutsummaryrefslogtreecommitdiff
path: root/src/shared/LockedQueue.h
diff options
context:
space:
mode:
authormaximius <none@none>2009-10-17 15:51:44 -0700
committermaximius <none@none>2009-10-17 15:51:44 -0700
commite585187b248f48b3c6e9247b49fa07c6565d65e5 (patch)
tree637c5b7ddacf41040bef4ea4f75a97da64c6a9bc /src/shared/LockedQueue.h
parent26b5e033ffde3d161382fc9addbfa99738379641 (diff)
*Backed out changeset 3be01fb200a5
--HG-- branch : trunk
Diffstat (limited to 'src/shared/LockedQueue.h')
-rw-r--r--src/shared/LockedQueue.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/shared/LockedQueue.h b/src/shared/LockedQueue.h
index 7585989fdd0..6543487da81 100644
--- a/src/shared/LockedQueue.h
+++ b/src/shared/LockedQueue.h
@@ -15,13 +15,16 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
#ifndef LOCKEDQUEUE_H
#define LOCKEDQUEUE_H
+
#include <ace/Guard_T.h>
#include <ace/Thread_Mutex.h>
#include <deque>
#include <assert.h>
#include "Errors.h"
+
namespace ACE_Based
{
template <class T, class LockType, typename StorageType=std::deque<T> >
@@ -29,41 +32,56 @@ namespace ACE_Based
{
//! Lock access to the queue.
LockType _lock;
+
//! Storage backing the queue.
StorageType _queue;
+
//! Cancellation flag.
volatile bool _canceled;
+
public:
+
//! Create a LockedQueue.
LockedQueue() : _canceled(false) {}
+
//! Destroy a LockedQueue.
virtual ~LockedQueue() { }
+
//! Adds an item to the queue.
void add(const T& item)
{
ACE_Guard<LockType> g(this->_lock);
+
//ASSERT(!this->_canceled);
// throw Cancellation_Exception();
+
_queue.push_back(item);
}
+
//! Gets the next result in the queue, if any.
bool next(T& result)
{
ACE_Guard<LockType> g(this->_lock);
+
if (_queue.empty())
return false;
+
//ASSERT (!_queue.empty() || !this->_canceled);
// throw Cancellation_Exception();
result = _queue.front();
_queue.pop_front();
+
return true;
}
+
//! Cancels the queue.
void cancel()
{
ACE_Guard<LockType> g(this->_lock);
+
_canceled = true;
}
+
//! Checks if the queue is cancelled.
bool cancelled()
{