#include <simgear/compiler.h>
-#if defined ( SG_HAVE_STD_INCLUDES )
-# include <cassert>
-#else
-# include <assert.h>
-#endif
-
+#include <cassert>
#include <queue>
-#include "SGThread.hxx"
-#include "SGGuard.hxx"
+#include <OpenThreads/Mutex>
+#include <OpenThreads/ScopedLock>
+#include <OpenThreads/Condition>
/**
* SGQueue defines an interface for a FIFO.
/**
* A simple thread safe queue. All access functions are guarded with a mutex.
*/
-template<class T, class SGLOCK=SGMutex>
+template<class T, class SGLOCK=OpenThreads::Mutex>
class SGLockedQueue : public SGQueue<T>
{
public:
* @return bool True if queue is empty, otherwisr false.
*/
virtual bool empty() {
- SGGuard<SGLOCK> g(mutex);
+ OpenThreads::ScopedLock<SGLOCK> g(mutex);
return this->fifo.empty();
}
* @param T object to add.
*/
virtual void push( const T& item ) {
- SGGuard<SGLOCK> g(mutex);
+ OpenThreads::ScopedLock<SGLOCK> g(mutex);
this->fifo.push( item );
}
* @return T next available object.
*/
virtual T front() {
- SGGuard<SGLOCK> g(mutex);
+ OpenThreads::ScopedLock<SGLOCK> g(mutex);
assert( ! this->fifo.empty() );
T item = this->fifo.front();
return item;
* @return T next available object.
*/
virtual T pop() {
- SGGuard<SGLOCK> g(mutex);
+ OpenThreads::ScopedLock<SGLOCK> g(mutex);
//if (fifo.empty()) throw NoSuchElementException();
assert( ! this->fifo.empty() );
// if (fifo.empty())
* @return size_t size of queue.
*/
virtual size_t size() {
- SGGuard<SGLOCK> g(mutex);
+ OpenThreads::ScopedLock<SGLOCK> g(mutex);
return this->fifo.size();
}
*
*/
virtual bool empty() {
- SGGuard<SGMutex> g(mutex);
+ OpenThreads::ScopedLock<OpenThreads::Mutex> g(mutex);
return this->fifo.empty();
}
* @param T object to add.
*/
virtual void push( const T& item ) {
- SGGuard<SGMutex> g(mutex);
+ OpenThreads::ScopedLock<OpenThreads::Mutex> g(mutex);
this->fifo.push( item );
not_empty.signal();
}
* @return T next available object.
*/
virtual T front() {
- SGGuard<SGMutex> g(mutex);
+ OpenThreads::ScopedLock<OpenThreads::Mutex> g(mutex);
assert(this->fifo.empty() != true);
//if (fifo.empty()) throw ??
* @return T next available object.
*/
virtual T pop() {
- SGGuard<SGMutex> g(mutex);
+ OpenThreads::ScopedLock<OpenThreads::Mutex> 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() {
- SGGuard<SGMutex> g(mutex);
+ OpenThreads::ScopedLock<OpenThreads::Mutex> g(mutex);
return this->fifo.size();
}
/**
* Mutex to serialise access.
*/
- SGMutex mutex;
+ OpenThreads::Mutex mutex;
/**
* Condition to signal when queue not empty.
*/
- SGPthreadCond not_empty;
+ OpenThreads::Condition not_empty;
private:
// Prevent copying.