Skip to content

Commit

Permalink
[09_queue] concurrency, concurrency_queue, init.
Browse files Browse the repository at this point in the history
  • Loading branch information
Liam0205 committed Oct 11, 2018
1 parent 2e8bbee commit 2aa9de5
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions c-cpp/09_queue/concurrency_queue.hpp
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_

0 comments on commit 2aa9de5

Please sign in to comment.