Scanner C++ API
queue.h
1 /* Copyright 2016 Carnegie Mellon University, NVIDIA Corporation
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <atomic>
19 #include <condition_variable>
20 #include <deque>
21 #include <mutex>
22 
23 #include "scanner/util/blockingconcurrentqueue.h"
24 
25 namespace scanner {
26 
27 using namespace moodycamel;
28 
29 template <typename T>
30 class Queue : public BlockingConcurrentQueue<T> {
31  public:
32  Queue(size_t size=8) : BlockingConcurrentQueue<T>(size) {}
33 
34  inline void clear() {
35  T t;
36  while (BlockingConcurrentQueue<T>::try_dequeue(t)) {}
37  }
38 
39  inline size_t size() {
40  return BlockingConcurrentQueue<T>::size_approx();
41  }
42 
43  inline void push(T item) {
44  bool success = BlockingConcurrentQueue<T>::enqueue(item);
45  LOG_IF(FATAL, !success) << "Queue push failed";
46  }
47 
48  inline void pop(T& item) {
49  BlockingConcurrentQueue<T>::wait_dequeue(item);
50  }
51 };
52 
53 }
Definition: database.cpp:36
Definition: queue.h:30