Tensor Comprehensions
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
concurrent_queue-inl.h
Go to the documentation of this file.
1 
16 #pragma once
17 
18 namespace tc {
19 namespace autotune {
20 
21 template <typename T>
23  {
24  std::lock_guard<std::mutex> lock(mtx_);
25  queue_.push(t);
26  }
27  cv_.notify_one();
28 }
29 
30 template <typename T>
31 T ConcurrentQueue<T>::dequeueWaitFor(std::chrono::steady_clock::duration d) {
32  std::unique_lock<std::mutex> lock(mtx_);
33  auto hasElements =
34  cv_.wait_for(lock, d, [&]() { return not queue_.empty(); });
35  if (not hasElements) {
36  return nullptr;
37  }
38  auto t = queue_.front();
39  queue_.pop();
40  return t;
41 }
42 
43 template <typename T>
45  std::lock_guard<std::mutex> lock(mtx_);
46  return queue_.empty();
47 }
48 
49 template <typename T>
50 size_t ConcurrentQueue<T>::size() const {
51  std::lock_guard<std::mutex> lock(mtx_);
52  return queue_.size();
53 }
54 
55 } // namespace autotune
56 } // namespace tc
size_t size() const
Definition: concurrent_queue-inl.h:50
void enqueue(T t)
Definition: concurrent_queue-inl.h:22
bool empty() const
Definition: concurrent_queue-inl.h:44
T dequeueWaitFor(std::chrono::steady_clock::duration)
Definition: concurrent_queue-inl.h:31