6 namespace honey {
namespace lockfree
39 _head(TaggedHandle(_freeList.handle(_freeList.construct(T())), 0)),
54 Node* node = _freeList.
construct(forward<T_>(val));
67 _tail.cas(TaggedHandle(next, tail.
nextTag()), tail);
71 if (_freeList.
deref(tail)->next.cas(TaggedHandle(_freeList.
handle(node), next.
nextTag()), next))
break;
74 _tail.cas(TaggedHandle(_freeList.
handle(node), tail.
nextTag()), tail);
92 if (!next)
return false;
94 _tail.cas(TaggedHandle(next, tail.
nextTag()), tail);
100 if (val) val = _freeList.
deref(next)->val;
102 if (_head.cas(TaggedHandle(next, head.
nextTag()), head))
break;
121 if (head.
handle() == tail && !next)
return false;
125 val = _freeList.
deref(next)->val;
144 _tail.cas(TaggedHandle(next, tail.
nextTag()), tail);
148 if (head.
handle() == tail)
return false;
150 val = _freeList.
deref(tail)->val;
160 bool empty()
const {
return !_size; }
~Queue()
Definition: Queue.h:43
bool front(T &val)
Get a copy of the next element that will be popped. Returns true on success, false if there is no ele...
Definition: Queue.h:111
Holds block handle and tag to prevent lock-free ABA issues.
Definition: Pool.h:95
T * construct(Args &&...args)
Construct object and remove from free list.
Definition: FreeList.h:35
Queue(szt capacity=0)
Definition: Queue.h:37
void reserve(szt capacity)
Ensure that enough storage is allocated for a number of objects.
Definition: FreeList.h:27
static optnull_t optnull
Null optional, use to reset an optional to an uninitialized state or test for initialization.
Definition: Optional.h:12
const Handle & handle() const
Definition: Pool.h:105
bool empty() const
Check whether the queue does not contain any elements.
Definition: Queue.h:160
Inherit to declare that class is not copyable.
Definition: Meta.h:286
szt capacity() const
The number of elements for which storage is allocated.
Definition: Queue.h:48
T value_type
Definition: Queue.h:35
Must be a load op. Synchronize with a prior release in another thread.
No order constraint, same as plain load/store. Unsafe but best performance.
void reserve(szt capacity)
Ensure that enough storage is allocated for a number of elements.
Definition: Queue.h:46
size_t szt
Size type, shorthand for size_t.
Definition: Core.h:90
void destroy(T *ptr)
Destroy object and add to free list.
Definition: FreeList.h:40
bool pop(optional< T & > val=optnull)
Remove oldest element from the queue and copy it into val. Returns true on success, false if there is no element to pop.
Definition: Queue.h:79
void clear()
Remove all elements.
Definition: Queue.h:157
szt size() const
The number of elements in the queue.
Definition: Queue.h:162
szt capacity() const
The number of objects for which storage is allocated.
Definition: FreeList.h:29
Specialization for references.
Definition: Optional.h:132
Lock-free FIFO queue. Uses auto-expanding freelist allocator so memory is only reclaimed upon destruc...
Definition: Queue.h:14
void push(T_ &&val)
Add new element constructed with val onto the end of the queue.
Definition: Queue.h:52
Int nextTag() const
Definition: Pool.h:107
T * deref(Handle handle) const
Get object from compressed handle.
Definition: FreeList.h:45
bool back(T &val)
Get a copy of the last element. Returns true on success, false if there is no element.
Definition: Queue.h:131
Handle handle(T *ptr) const
Get compressed handle for object.
Definition: FreeList.h:43
Global Honeycomb namespace.