olp-cpp-sdk  1.21.0
SyncQueue.h
1 /*
2  * Copyright (C) 2019-2021 HERE Europe B.V.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  * License-Filename: LICENSE
18  */
19 
20 #pragma once
21 
22 #include <condition_variable>
23 #include <deque>
24 #include <mutex>
25 #include <queue>
26 
27 #include <olp/core/CoreApi.h>
28 
29 namespace olp {
30 namespace thread {
31 
44 template <typename T, typename Container>
45 class CORE_API SyncQueue final {
46  public:
47  SyncQueue() noexcept;
48  ~SyncQueue();
49 
51  SyncQueue(const SyncQueue&) = delete;
53  SyncQueue& operator=(const SyncQueue&) = delete;
55  SyncQueue(SyncQueue&&) = delete;
58 
64  bool Empty() const;
65 
70  void Close();
71 
80  bool Pull(T& element);
81 
87  void Push(T&& element);
88 
94  void Push(const T& element);
95 
96  private:
98  Container queue_;
100  mutable std::mutex mutex_;
102  std::condition_variable ready_;
105  bool closed_;
106 };
107 
109 template <typename T>
111 
112 } // namespace thread
113 } // namespace olp
114 
115 #include "SyncQueue.inl"
A thread-safe container adapter.
Definition: SyncQueue.h:45
SyncQueue & operator=(const SyncQueue &)=delete
Non-copyable, non-movable.
SyncQueue(const SyncQueue &)=delete
Non-copyable, non-movable.
SyncQueue & operator=(SyncQueue &&)=delete
Non-copyable, non-movable.
SyncQueue(SyncQueue &&)=delete
Non-copyable, non-movable.
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24