#include <cassert>
#include <queue>
-#include <OpenThreads/Mutex>
-#include <OpenThreads/ScopedLock>
-#include <OpenThreads/Condition>
+#include "SGGuard.hxx"
+#include "SGThread.hxx"
/**
* SGQueue defines an interface for a FIFO.
protected:
/**
- *
+ *
*/
std::queue<T> fifo;
};
/**
* A simple thread safe queue. All access functions are guarded with a mutex.
*/
-template<class T, class SGLOCK=OpenThreads::Mutex>
+template<class T>
class SGLockedQueue : public SGQueue<T>
{
public:
* @return bool True if queue is empty, otherwisr false.
*/
virtual bool empty() {
- OpenThreads::ScopedLock<SGLOCK> g(mutex);
+ SGGuard<SGMutex> g(mutex);
return this->fifo.empty();
}
* @param T object to add.
*/
virtual void push( const T& item ) {
- OpenThreads::ScopedLock<SGLOCK> g(mutex);
+ SGGuard<SGMutex> g(mutex);
this->fifo.push( item );
}
* @return T next available object.
*/
virtual T front() {
- OpenThreads::ScopedLock<SGLOCK> g(mutex);
+ SGGuard<SGMutex> g(mutex);
assert( ! this->fifo.empty() );
T item = this->fifo.front();
return item;
* @return T next available object.
*/
virtual T pop() {
- OpenThreads::ScopedLock<SGLOCK> g(mutex);
+ SGGuard<SGMutex> g(mutex);
//if (fifo.empty()) throw NoSuchElementException();
assert( ! this->fifo.empty() );
// if (fifo.empty())
* @return size_t size of queue.
*/
virtual size_t size() {
- OpenThreads::ScopedLock<SGLOCK> g(mutex);
+ SGGuard<SGMutex> g(mutex);
return this->fifo.size();
}
/**
* Mutex to serialise access.
*/
- SGLOCK mutex;
+ SGMutex mutex;
private:
// Prevent copying.
~SGBlockingQueue() {}
/**
- *
+ *
*/
virtual bool empty() {
- OpenThreads::ScopedLock<OpenThreads::Mutex> g(mutex);
+ SGGuard<SGMutex> g(mutex);
return this->fifo.empty();
}
* @param T object to add.
*/
virtual void push( const T& item ) {
- OpenThreads::ScopedLock<OpenThreads::Mutex> g(mutex);
+ SGGuard<SGMutex> g(mutex);
this->fifo.push( item );
not_empty.signal();
}
* @return T next available object.
*/
virtual T front() {
- OpenThreads::ScopedLock<OpenThreads::Mutex> g(mutex);
+ SGGuard<SGMutex> g(mutex);
assert(this->fifo.empty() != true);
//if (fifo.empty()) throw ??
* @return T next available object.
*/
virtual T pop() {
- OpenThreads::ScopedLock<OpenThreads::Mutex> g(mutex);
+ SGGuard<SGMutex> g(mutex);
while (this->fifo.empty())
- not_empty.wait(&mutex);
+ not_empty.wait(mutex);
assert(this->fifo.empty() != true);
//if (fifo.empty()) throw ??
* @return size_t size of queue.
*/
virtual size_t size() {
- OpenThreads::ScopedLock<OpenThreads::Mutex> g(mutex);
+ SGGuard<SGMutex> g(mutex);
return this->fifo.size();
}
/**
* Mutex to serialise access.
*/
- OpenThreads::Mutex mutex;
+ SGMutex mutex;
/**
* Condition to signal when queue not empty.
*/
- OpenThreads::Condition not_empty;
+ SGWaitCondition not_empty;
private:
// Prevent copying.
~SGBlockingDeque() {}
/**
- *
+ *
+ */
+ virtual void clear() {
+ SGGuard<SGMutex> g(mutex);
+ this->queue.clear();
+ }
+
+ /**
+ *
*/
virtual bool empty() {
- OpenThreads::ScopedLock<OpenThreads::Mutex> g(mutex);
+ SGGuard<SGMutex> g(mutex);
return this->queue.empty();
}
* @param T object to add.
*/
virtual void push_front( const T& item ) {
- OpenThreads::ScopedLock<OpenThreads::Mutex> g(mutex);
+ SGGuard<SGMutex> g(mutex);
this->queue.push_front( item );
not_empty.signal();
}
* @param T object to add.
*/
virtual void push_back( const T& item ) {
- OpenThreads::ScopedLock<OpenThreads::Mutex> g(mutex);
+ SGGuard<SGMutex> g(mutex);
this->queue.push_back( item );
not_empty.signal();
}
* @return T next available object.
*/
virtual T front() {
- OpenThreads::ScopedLock<OpenThreads::Mutex> g(mutex);
+ SGGuard<SGMutex> g(mutex);
assert(this->queue.empty() != true);
//if (queue.empty()) throw ??
* @return T next available object.
*/
virtual T pop_front() {
- OpenThreads::ScopedLock<OpenThreads::Mutex> g(mutex);
+ SGGuard<SGMutex> g(mutex);
while (this->queue.empty())
- not_empty.wait(&mutex);
+ not_empty.wait(mutex);
assert(this->queue.empty() != true);
//if (queue.empty()) throw ??
* @return T next available object.
*/
virtual T pop_back() {
- OpenThreads::ScopedLock<OpenThreads::Mutex> g(mutex);
+ SGGuard<SGMutex> g(mutex);
while (this->queue.empty())
- not_empty.wait(&mutex);
+ not_empty.wait(mutex);
assert(this->queue.empty() != true);
//if (queue.empty()) throw ??
* @return size_t size of queue.
*/
virtual size_t size() {
- OpenThreads::ScopedLock<OpenThreads::Mutex> g(mutex);
+ SGGuard<SGMutex> g(mutex);
return this->queue.size();
}
/**
* Mutex to serialise access.
*/
- OpenThreads::Mutex mutex;
+ SGMutex mutex;
/**
* Condition to signal when queue not empty.
*/
- OpenThreads::Condition not_empty;
+ SGWaitCondition not_empty;
private:
// Prevent copying.