32 for (
size_t i = 1; i <=
sizeof(
void*) * 4; i <<= 1)
39 for (
size_t i = 0; i <
capacity; ++i) {
40 p_node[i].
tail.store(i, std::memory_order_relaxed);
41 p_node[i].
head.store(-1, std::memory_order_relaxed);
44 tail_pos.store(0, std::memory_order_relaxed);
45 head_pos.store(0, std::memory_order_relaxed);
51 size_t head =
head_pos.load(std::memory_order_acquire);
52 return tail_pos.load(std::memory_order_relaxed) - head;
61 size_t tail =
tail_pos.load(std::memory_order_relaxed);
64 if (node->
tail.load(std::memory_order_relaxed) != tail)
return false;
65 if ((
tail_pos.compare_exchange_weak(tail, tail + 1,
66 std::memory_order_relaxed)))
69 new (&node->
data) T(data);
70 node->
head.store(tail, std::memory_order_release);
80 size_t head =
head_pos.load(std::memory_order_relaxed);
83 if (node->
head.load(std::memory_order_relaxed) != head)
return false;
84 if (
head_pos.compare_exchange_weak(head, head + 1,
85 std::memory_order_relaxed))
Memory allocateator which uses malloc.
Definition: Allocator.h:21
A simple single producer, single consumer lock free queue.
Definition: QueueLockFree.h:14
void clear()
Definition: QueueLockFree.h:94
Vector< Node > vector
Definition: QueueLockFree.h:111
bool dequeue(const T &&data)
Definition: QueueLockFree.h:74
void resize(size_t capacity)
Definition: QueueLockFree.h:30
size_t size() const
Definition: QueueLockFree.h:50
~QueueLockFree()
Definition: QueueLockFree.h:21
size_t capacity() const
Definition: QueueLockFree.h:48
bool enqueue(T &data)
Definition: QueueLockFree.h:59
QueueLockFree(size_t capacity, Allocator &allocator=DefaultAllocator)
Definition: QueueLockFree.h:16
size_t capacity_value
Definition: QueueLockFree.h:108
bool enqueue(T &&data)
Definition: QueueLockFree.h:55
std::atomic< size_t > tail_pos
Definition: QueueLockFree.h:109
size_t capacity_mask
Definition: QueueLockFree.h:107
std::atomic< size_t > head_pos
Definition: QueueLockFree.h:110
bool dequeue(T &result)
Definition: QueueLockFree.h:78
Node * p_node
Definition: QueueLockFree.h:106
void setAllocator(Allocator &allocator)
Definition: QueueLockFree.h:28
Vector implementation which provides the most important methods as defined by std::vector....
Definition: Vector.h:21
Definition: Allocator.h:6
Definition: QueueLockFree.h:100
std::atomic< size_t > head
Definition: QueueLockFree.h:103
std::atomic< size_t > tail
Definition: QueueLockFree.h:102
T data
Definition: QueueLockFree.h:101