Wayverb
threaded_queue.h
1 #pragma once
2 
3 #include "utilities/threading_policies.h"
4 
5 #include <queue>
6 #include <experimental/optional>
7 
8 namespace util {
9 
10 template <typename ThreadingPolicy, typename T>
11 class threaded_queue final {
12 public:
13  using value_type = T;
14 
15  void push(value_type value) {
16  const auto lck = threading_policy_.get_lock();
17  queue_.push(std::move(value));
18  }
19 
20  std::experimental::optional<value_type> pop() {
21  const auto lck = threading_policy_.get_lock();
22  if (queue_.empty()) {
23  return std::experimental::nullopt;
24  }
25  auto ret = std::move(queue_.front());
26  queue_.pop();
27  return ret;
28  }
29 
30  void clear() {
31  const auto lck = threading_policy_.get_lock();
32  queue_ = std::queue<value_type>{};
33  }
34 
35 private:
36  ThreadingPolicy threading_policy_;
37  std::queue<value_type> queue_;
38 };
39 
40 } // namespace util
Definition: allocator.h:6
Definition: threaded_queue.h:11