CppLogging  1.0.4.0
C++ Logging Library
async_wait_free_queue.h
Go to the documentation of this file.
1 
9 #ifndef CPPLOGGING_PROCESSORS_ASYNC_WAIT_FREE_QUEUE_H
10 #define CPPLOGGING_PROCESSORS_ASYNC_WAIT_FREE_QUEUE_H
11 
12 #include "logging/record.h"
13 
14 #include <atomic>
15 #include <cassert>
16 #include <cstdio>
17 #include <cstring>
18 #include <utility>
19 
20 namespace CppLogging {
21 
23 
34 template<typename T>
36 {
37 public:
39 
42  explicit AsyncWaitFreeQueue(size_t capacity);
45  ~AsyncWaitFreeQueue() { delete[] _buffer; }
46 
49 
51  explicit operator bool() const noexcept { return !empty(); }
52 
54  bool empty() const noexcept { return (size() == 0); }
56  size_t capacity() const noexcept { return _capacity; }
58  size_t size() const noexcept;
59 
61 
65  bool Enqueue(Record& record);
66 
68 
72  bool Dequeue(Record& record);
73 
74 private:
75  struct Node
76  {
77  std::atomic<size_t> sequence;
78  Record value;
79  };
80 
81  typedef char cache_line_pad[128];
82 
83  cache_line_pad _pad0;
84  const size_t _capacity;
85  const size_t _mask;
86  Node* const _buffer;
87 
88  cache_line_pad _pad1;
89  std::atomic<size_t> _head;
90  cache_line_pad _pad2;
91  std::atomic<size_t> _tail;
92  cache_line_pad _pad3;
93 };
94 
95 } // namespace CppLogging
96 
98 
99 #endif // CPPLOGGING_PROCESSORS_ASYNC_WAIT_FREE_QUEUE_H
Asynchronous wait-free logging ring queue inline implementation.
Asynchronous wait-free logging ring queue.
AsyncWaitFreeQueue & operator=(AsyncWaitFreeQueue &&)=delete
AsyncWaitFreeQueue(size_t capacity)
Default class constructor.
AsyncWaitFreeQueue(const AsyncWaitFreeQueue &)=delete
size_t size() const noexcept
Get ring queue size.
bool Enqueue(Record &record)
Enqueue and swap the logging record into the ring queue (multiple producers threads method)
bool empty() const noexcept
Is ring queue empty?
AsyncWaitFreeQueue & operator=(const AsyncWaitFreeQueue &)=delete
AsyncWaitFreeQueue(AsyncWaitFreeQueue &&)=delete
bool Dequeue(Record &record)
Dequeue and swap the logging record from the ring queue (multiple consumers threads method)
size_t capacity() const noexcept
Get ring queue capacity.
Logging record.
Definition: record.h:37
C++ Logging project definitions.
Definition: appender.h:15
Logging record definition.