Utilities
Utilities header only library
AtomicQueue.h
1 /*
2  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
3  Unauthorized copying of this file, via any medium is strictly prohibited
4  Proprietary and confidential
5 */
6 #ifndef UTILS_ATOMIC_QUEUE_H
7 #define UTILS_ATOMIC_QUEUE_H
8 #include <queue>
9 #include <mutex>
10 
11 namespace std_ext
12 {
13 
15  template <typename T>
17  {
18  public:
20  T &GetNext()
21  {
22  std::lock_guard<std::mutex> lock(mutex_);
23  return this->queue_.front();
24  }
26  T Pop()
27  {
28  std::lock_guard<std::mutex> lock(mutex_);
29  T value = this->queue_.front();
30  this->queue_.pop();
31  return value;
32  }
34  void Push(T value)
35  {
36  std::lock_guard<std::mutex> lock(mutex_);
37  this->queue_.push(value);
38  }
40  bool IsEmpty() const
41  {
42  std::lock_guard<std::mutex> lock(mutex_);
43  bool check = this->queue_.empty();
44  return check;
45  }
47  size_t GetSize() const
48  {
49  std::lock_guard<std::mutex> lock(mutex_);
50  return this->queue_.size();
51  }
52  private:
53  mutable std::mutex mutex_;
54  std::queue<T> queue_;
55  };
56 
57 }
58 #endif /* !UTILS_ATOMIC_QUEUE_H */
size_t GetSize() const
Get the number of records currently in the queue.
Definition: AtomicQueue.h:47
Queue which allows calling members from multiple threads without interference.
Definition: AtomicQueue.h:16
T & GetNext()
Get next record from queue.
Definition: AtomicQueue.h:20
Extensions to the standard libraries.
Definition: AtomicQueue.h:11
bool IsEmpty() const
Check, whether the queue is empty.
Definition: AtomicQueue.h:40
T Pop()
Get next record from queue and remove it from the queue.
Definition: AtomicQueue.h:26
void Push(T value)
Add new record to queue.
Definition: AtomicQueue.h:34