Subversion Repositories HomeAutomation

Rev

Rev 1318 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1318 Rev 1403
Line 22... Line 22...
22
namespace thread {
22
namespace thread {
23
 
23
 
24
template<typename T>
24
template<typename T>
25
class Queue
25
class Queue
26
{
26
{
27
    typedef boost::mutex::scoped_lock lock;
-
 
28
 
-
 
29
public:
27
public:
30
    Queue()
28
    Queue() { }
31
    {
-
 
32
    }
-
 
33
 
-
 
34
    ~Queue()
29
    ~Queue() { }
35
    {
-
 
36
    }
-
 
37
 
30
 
38
    void push(T item)
31
    void Push(T item)
39
    {
32
    {
40
        lock guard(this->myMutex);
33
        boost::mutex::scoped_lock guard(this->guard_mutex_);
-
 
34
 
41
        this->myQueue.push(item);
35
        this->queue_.push(item);
42
    }
36
    }
43
 
37
 
44
    T pop()
38
    T pop()
45
    {
39
    {
46
        lock guard(this->myMutex);
40
        boost::mutex::scoped_lock guard(this->guard_mutex_);
-
 
41
 
47
        T item = this->myQueue.front();
42
        T item = this->queue_.front();
48
        this->myQueue.pop();
43
        this->queue_.pop();
49
        return item;
44
        return item;
50
    }
45
    }
51
 
46
 
52
    unsigned int size()
47
    unsigned int size()
53
    {
48
    {
54
        lock guard(this->myMutex);
49
        boost::mutex::scoped_lock guard(this->guard_mutex_);
-
 
50
 
55
        return this->myQueue.size();
51
        return this->queue_.size();
56
    }
52
    }
57
 
53
 
58
private:
54
private:
59
    std::queue<T> myQueue;
55
    std::queue<T> queue_;
60
    boost::mutex myMutex;
56
    boost::mutex guard_mutex_;
61
};
57
};
62
 
58
 
63
}
59
} // namespace thread
64
}
60
} // namespace atom
65
 
61
 
66
#endif /* QUEUE_H_ */
62
#endif /* QUEUE_HPP_ */
67
 
63