NVIDIA DeepStream SDK API Reference

7.0 Release
concurrent_queue.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2020 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  *
5  * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
6  * property and proprietary rights in and to this material, related
7  * documentation and any modifications thereto. Any use, reproduction,
8  * disclosure or distribution of this material and related documentation
9  * without an express license agreement from NVIDIA CORPORATION or
10  * its affiliates is strictly prohibited.
11  */
12 
13 #pragma once
14 
15 #include <queue>
16 #include <mutex>
17 
21 template <typename T>
23 {
24 public:
25  void push(const T &elm);
26  T pop();
27  bool is_empty();
28 
29 private:
30  std::queue<T> queue_;
31  std::mutex mutex_;
32 };
33 
34 template <typename T>
35 void ConcurrentQueue<T>::push(const T &elm)
36 {
37  mutex_.lock();
38  queue_.push(elm);
39  mutex_.unlock();
40 }
41 
42 template <typename T>
44 {
45  mutex_.lock();
46  T elm = queue_.front();
47  queue_.pop();
48  mutex_.unlock();
49  return elm;
50 }
51 
52 template <typename T>
54 {
55  mutex_.lock();
56  bool res = queue_.empty();
57  mutex_.unlock();
58  return res;
59 }
ConcurrentQueue
Simple concurrent Queue class using an stl queue.
Definition: concurrent_queue.h:22
ConcurrentQueue::push
void push(const T &elm)
Definition: concurrent_queue.h:35
ConcurrentQueue::pop
T pop()
Definition: concurrent_queue.h:43
ConcurrentQueue::is_empty
bool is_empty()
Definition: concurrent_queue.h:53