forked from wangzheng0822/algo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[09_queue] concurrency, concurrency_queue, init.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Created by Liam Huang (Liam0205) on 2018/10/11. | ||
*/ | ||
|
||
#ifndef QUEUE_CONCURRENCY_QUEUE_HPP_ | ||
#define QUEUE_CONCURRENCY_QUEUE_HPP_ | ||
|
||
#include <queue> | ||
#include <mutex> | ||
|
||
template <typename T> | ||
class ConcurrencyQueue { | ||
public: | ||
using value_type = T; | ||
using container_type = std::queue<value_type>; | ||
using size_type = typename container_type::size_type; | ||
|
||
private: | ||
container_type container_; | ||
mutable std::mutex mutex_; | ||
|
||
public: | ||
ConcurrencyQueue() = default; | ||
ConcurrencyQueue(const ConcurrencyQueue&) = default; | ||
ConcurrencyQueue(ConcurrencyQueue&&) = default; | ||
ConcurrencyQueue& operator=(const ConcurrencyQueue&) = default; | ||
ConcurrencyQueue& operator=(ConcurrencyQueue&&) = default; | ||
|
||
private: | ||
bool empty() const { return container_.empty(); } | ||
}; | ||
|
||
#endif // QUEUE_CONCURRENCY_QUEUE_HPP_ | ||
|