Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

  1. /*
  2.  * TSQueue.hpp
  3.  *
  4.  *  Created on: Apr 27, 2009
  5.  *      Author: Mattias Runge
  6.  */
  7.  
  8. #ifndef TSQUEUE_HPP_
  9. #define TSQUEUE_HPP_
  10.  
  11. #include <queue>
  12. #include <boost/thread.hpp>
  13. #include <boost/thread/mutex.hpp>
  14. #include <boost/thread/locks.hpp>
  15.  
  16. namespace atom {
  17. namespace utils {
  18.  
  19. using namespace std;
  20.  
  21. template<class T>
  22. class TSQueue
  23. {
  24.     typedef boost::mutex::scoped_lock lock;
  25.  
  26. public:
  27.     TSQueue()
  28.     {
  29.     }
  30.  
  31.     ~TSQueue()
  32.     {
  33.     }
  34.  
  35.     void push(T item)
  36.     {
  37.         lock guard(this->mutex);
  38.         this->_queue.push(item);
  39.     }
  40.  
  41.     T pop()
  42.     {
  43.         lock guard(this->mutex);
  44.         T item = this->_queue.front();
  45.         this->_queue.pop();
  46.         return item;
  47.     }
  48.  
  49.     int size()
  50.     {
  51.         lock guard(this->mutex);
  52.         return this->_queue.size();
  53.     }
  54.  
  55. private:
  56.     queue<T> _queue;
  57.     boost::mutex mutex;
  58. };
  59.  
  60. }
  61. }
  62.  
  63. #endif /* TSQUEUE_HPP_ */
  64.  
  65.