Created
December 18, 2017 03:28
-
-
Save phrz/c2d0c767aaf6e98f3a53c53231a8e40c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template<typename T> | |
| class ConcurrentQueue { | |
| protected: | |
| mutable std::mutex queue_mutex; | |
| std::queue<T> queue; | |
| [[nodiscard]] auto getLock() { | |
| return std::lock_guard<std::mutex>(this->queue_mutex); | |
| } | |
| public: | |
| // empty | |
| bool empty() { | |
| auto lock = getLock(); | |
| return queue.empty(); | |
| } | |
| // front | |
| T& front() { | |
| auto lock = getLock(); | |
| return queue.front(); | |
| } | |
| // push | |
| void push(const T& value) { | |
| auto lock = getLock(); | |
| return queue.push(value); | |
| } | |
| void push(T&& value) { | |
| auto lock = getLock(); | |
| return queue.push(value); | |
| } | |
| // pop | |
| void pop() { | |
| auto lock = getLock(); | |
| queue.pop(); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment