]> git.mxchange.org Git - simgear.git/blobdiff - simgear/threads/SGQueue.hxx
Modified Files:
[simgear.git] / simgear / threads / SGQueue.hxx
index 9d4dcf31259840442a6f697c23aacd730b52956f..9f534ec909a34e53b01e99c0e8f42b85fcaa0989 100644 (file)
@@ -61,6 +61,13 @@ public:
      */
     virtual T pop() = 0;
 
+    /**
+     * Query the size of the queue
+     *
+     * @return size_t size of queue.
+     */
+    virtual size_t size() = 0;
+
 protected:
     /**
      * 
@@ -93,7 +100,7 @@ public:
      */
     virtual bool empty() {
        SGGuard<SGLOCK> g(mutex);
-       return fifo.empty();
+       return this->fifo.empty();
     }
 
     /**
@@ -103,7 +110,7 @@ public:
      */
     virtual void push( const T& item ) {
        SGGuard<SGLOCK> g(mutex);
-       fifo.push( item );
+       this->fifo.push( item );
     }
 
     /**
@@ -113,8 +120,8 @@ public:
      */
     virtual T front() {
        SGGuard<SGLOCK> g(mutex);
-       assert( ! fifo.empty() );
-       T item = fifo.front();
+       assert( ! this->fifo.empty() );
+       T item = this->fifo.front();
        return item;
     }
 
@@ -126,16 +133,27 @@ public:
     virtual T pop() {
        SGGuard<SGLOCK> g(mutex);
        //if (fifo.empty()) throw NoSuchElementException();
-       assert( ! fifo.empty() );
+       assert( ! this->fifo.empty() );
 //     if (fifo.empty())
 //     {
 //         mutex.unlock();
 //         pthread_exit( PTHREAD_CANCELED );
 //     }
-       T item = fifo.front();
-       fifo.pop();
+       T item = this->fifo.front();
+       this->fifo.pop();
        return item;
     }
+
+    /**
+     * Query the size of the queue
+     *
+     * @return size_t size of queue.
+     */
+    virtual size_t size() {
+       SGGuard<SGLOCK> g(mutex);
+        return this->fifo.size();
+    }
+
 private:
 
     /**
@@ -165,14 +183,14 @@ public:
     /**
      * Destroy this queue.
      */
-    ~SGBlockingQueue() { mutex.unlock(); }
+    ~SGBlockingQueue() {}
 
     /**
      * 
      */
     virtual bool empty() {
        SGGuard<SGMutex> g(mutex);
-       return fifo.empty();
+       return this->fifo.empty();
     }
 
     /**
@@ -182,7 +200,7 @@ public:
      */
     virtual void push( const T& item ) {
        SGGuard<SGMutex> g(mutex);
-       fifo.push( item );
+       this->fifo.push( item );
        not_empty.signal();
     }
 
@@ -195,10 +213,10 @@ public:
     virtual T front() {
        SGGuard<SGMutex> g(mutex);
 
-       assert(fifo.empty() != true);
+       assert(this->fifo.empty() != true);
        //if (fifo.empty()) throw ??
 
-       T item = fifo.front();
+       T item = this->fifo.front();
        return item;
     }
 
@@ -211,17 +229,27 @@ public:
     virtual T pop() {
        SGGuard<SGMutex> g(mutex);
 
-       while (fifo.empty())
+       while (this->fifo.empty())
            not_empty.wait(mutex);
 
-       assert(fifo.empty() != true);
+       assert(this->fifo.empty() != true);
        //if (fifo.empty()) throw ??
 
-       T item = fifo.front();
-       fifo.pop();
+       T item = this->fifo.front();
+       this->fifo.pop();
        return item;
     }
 
+    /**
+     * Query the size of the queue
+     *
+     * @return size_t size of queue.
+     */
+    virtual size_t size() {
+       SGGuard<SGMutex> g(mutex);
+        return this->fifo.size();
+    }
+
 private:
 
     /**