Rev 1309 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1309 | Rev 1317 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | /* |
1 | /* |
| 2 | * |
2 | * Queue.h |
| 3 | * |
3 | * |
| 4 | * Created on: Apr 27, 2009 |
4 | * Created on: Apr 27, 2009 |
| 5 | * Author: Mattias Runge |
5 | * Author: Mattias Runge |
| 6 | */ |
6 | */ |
| 7 | 7 | ||
| 8 | #ifndef |
8 | #ifndef QUEUE_H_ |
| 9 | #define |
9 | #define QUEUE_H_ |
| 10 | 10 | ||
| 11 | #include <queue> |
11 | #include <queue> |
| 12 | #include <boost/thread.hpp> |
12 | #include <boost/thread.hpp> |
| 13 | #include <boost/thread/mutex.hpp> |
13 | #include <boost/thread/mutex.hpp> |
| 14 | #include <boost/thread/locks.hpp> |
14 | #include <boost/thread/locks.hpp> |
| 15 | 15 | ||
| 16 | namespace atom { |
16 | namespace atom { |
| 17 | namespace |
17 | namespace thread { |
| 18 | 18 | ||
| 19 | using namespace std; |
19 | using namespace std; |
| 20 | 20 | ||
| 21 | template< |
21 | template<typename T> |
| 22 | class |
22 | class Queue |
| 23 | { |
23 | { |
| 24 | typedef boost::mutex::scoped_lock lock; |
24 | typedef boost::mutex::scoped_lock lock; |
| 25 | 25 | ||
| 26 | public: |
26 | public: |
| 27 |
|
27 | Queue(); |
| 28 | { |
- | |
| 29 | } |
- | |
| 30 | - | ||
| 31 |
|
28 | ~Queue(); |
| 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 | 29 | ||
| 49 |
|
30 | void push(T item); |
| 50 | |
31 | T pop(); |
| 51 | lock guard(this->mutex); |
- | |
| 52 |
|
32 | unsigned int size(); |
| 53 | } |
- | |
| 54 | 33 | ||
| 55 | private: |
34 | private: |
| 56 | queue<T> |
35 | std::queue<T> myQueue; |
| 57 | boost::mutex |
36 | boost::mutex myMutex; |
| 58 | }; |
37 | }; |
| 59 | 38 | ||
| 60 | } |
39 | } |
| 61 | } |
40 | } |
| 62 | 41 | ||
| 63 | #endif /* |
42 | #endif /* QUEUE_H_ */ |
| 64 | 43 | ||