Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

/home/pauldt/projects/IDEA/IDEA-ALL/IDEA-DEV/Core/Agent/Includes/Queue.hh

Go to the documentation of this file.
00001 // -*- Mode: c++ -*-
00002 //     File: $Source: /home/cvs/ISG-Repository/IDEA-DEV/Core/Agent/Includes/Queue.hh,v $
00003 //      Tag: $Name: DR_01_11_06 $
00004 //      CVS: $Id: Queue.hh,v 1.4 2005/12/30 22:05:34 rijsman Exp $
00005 //     Info: $CVSROOT/IDEA-DEV/COPYRIGHT
00006 
00007 #ifndef _HEADER_THREAD_SAFE_QUEUE_HEADER__
00008 #define _HEADER_THREAD_SAFE_QUEUE_HEADER__
00009 
00010 #include <assert.h>
00011 
00012 /* STL-INCLUDES */
00013 #include <queue>
00014 #include <vector>
00015 
00016 #include "ThreadTools.hh"
00017 
00018 namespace IDEA
00019 {
00029   template<class Type, class Container = std::vector< Type >, class Compare = std::less< typename Container::value_type > >
00030   class ThreadSafeQueue
00031   {
00032   public:
00036     ThreadSafeQueue():
00037       m_Mutex("ThreadSafeQueue") 
00038     {
00039     }
00040   
00044     ~ThreadSafeQueue() 
00045     {
00046     }
00047 
00053     inline bool empty()
00054     {
00055       Guard<RecursiveThreadMutex> guard(m_Mutex, "ThreadSafeQueue::empty");
00056 
00057       return m_Queue.empty();
00058     }
00059 
00063     inline const Type& top() 
00064     {
00065       Guard<RecursiveThreadMutex> guard(m_Mutex, "ThreadSafeQueue::top");
00066 
00067       return m_Queue.top();
00068     }
00069 
00073     inline void pop()
00074     {  
00075       Guard<RecursiveThreadMutex> guard(m_Mutex, "ThreadSafeQueue::pop");
00076 
00077       m_Queue.pop();
00078     }
00079 
00083     inline void push(const Type& v ) 
00084     { 
00085       Guard<RecursiveThreadMutex> guard(m_Mutex, "ThreadSafeQueue::push");
00086 
00087       m_Queue.push( v );
00088     };
00089 
00093     inline size_t size() 
00094     {
00095       Guard<RecursiveThreadMutex> guard(m_Mutex, "ThreadSafeQueue::size" );
00096 
00097       return m_Queue.size();
00098     }
00099 
00103     inline size_t size() const
00104     {
00105       Guard<RecursiveThreadMutex> guard(m_Mutex, "ThreadSafeQueue::size");
00106 
00107       return m_Queue.size();    
00108     }
00109   
00113     RecursiveThreadMutex& getMutex() { return m_Mutex; }
00114   private:
00115     RecursiveThreadMutex m_Mutex; 
00117     std::priority_queue<Type,Container,Compare> m_Queue; 
00118   };
00119 } //namespace IDEA
00120 
00121 #endif  //_HEADER_THREAD_SAFE_QUEUE_HEADER__
00122 

Contact information
© IDEA
Generated on Fri Feb 3 17:09:40 2006 for IDEA.