]> git.mxchange.org Git - simgear.git/blobdiff - simgear/threads/SGQueue.hxx
Modified Files:
[simgear.git] / simgear / threads / SGQueue.hxx
index 25fa2ca5b1db56d603be94c1362b2f3726354279..9f534ec909a34e53b01e99c0e8f42b85fcaa0989 100644 (file)
@@ -47,6 +47,13 @@ public:
      */
     virtual void push( const T& item ) = 0;
 
+    /**
+     * View the item from the head of the queue.
+     *
+     * @return T next available object.
+     */
+    virtual T front() = 0;
+
     /**
      * Get an item from the head of the queue.
      *
@@ -54,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:
     /**
      * 
@@ -86,7 +100,7 @@ public:
      */
     virtual bool empty() {
        SGGuard<SGLOCK> g(mutex);
-       return fifo.empty();
+       return this->fifo.empty();
     }
 
     /**
@@ -96,7 +110,19 @@ public:
      */
     virtual void push( const T& item ) {
        SGGuard<SGLOCK> g(mutex);
-       fifo.push( item );
+       this->fifo.push( item );
+    }
+
+    /**
+     * View the item from the head of the queue.
+     *
+     * @return T next available object.
+     */
+    virtual T front() {
+       SGGuard<SGLOCK> g(mutex);
+       assert( ! this->fifo.empty() );
+       T item = this->fifo.front();
+       return item;
     }
 
     /**
@@ -107,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:
 
     /**
@@ -146,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();
     }
 
     /**
@@ -163,10 +200,26 @@ public:
      */
     virtual void push( const T& item ) {
        SGGuard<SGMutex> g(mutex);
-       fifo.push( item );
+       this->fifo.push( item );
        not_empty.signal();
     }
 
+    /**
+     * View the item from the head of the queue.
+     * Calling thread is not suspended
+     *
+     * @return T next available object.
+     */
+    virtual T front() {
+       SGGuard<SGMutex> g(mutex);
+
+       assert(this->fifo.empty() != true);
+       //if (fifo.empty()) throw ??
+
+       T item = this->fifo.front();
+       return item;
+    }
+
     /**
      * Get an item from the head of the queue.
      * If no items are available then the calling thread is suspended
@@ -176,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:
 
     /**