From: curt Date: Sat, 28 Feb 2004 18:51:20 +0000 (+0000) Subject: Add front() methods SGQueue, SGLockedQueue, and SGBlockingQueue so that the X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=79d72b6292858b957d706171939136e627b29773;p=simgear.git Add front() methods SGQueue, SGLockedQueue, and SGBlockingQueue so that the can be used more interchangably with a regular STL queue. --- diff --git a/simgear/threads/SGQueue.hxx b/simgear/threads/SGQueue.hxx index 25fa2ca5..9d4dcf31 100644 --- a/simgear/threads/SGQueue.hxx +++ b/simgear/threads/SGQueue.hxx @@ -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. * @@ -99,6 +106,18 @@ public: fifo.push( item ); } + /** + * View the item from the head of the queue. + * + * @return T next available object. + */ + virtual T front() { + SGGuard g(mutex); + assert( ! fifo.empty() ); + T item = fifo.front(); + return item; + } + /** * Get an item from the head of the queue. * @@ -167,6 +186,22 @@ public: 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 g(mutex); + + assert(fifo.empty() != true); + //if (fifo.empty()) throw ?? + + T item = fifo.front(); + return item; + } + /** * Get an item from the head of the queue. * If no items are available then the calling thread is suspended