25#ifndef PXR_BASE_TRACE_CONCURRENT_LIST_H
26#define PXR_BASE_TRACE_CONCURRENT_LIST_H
32#include <tbb/cache_aligned_allocator.h>
37PXR_NAMESPACE_OPEN_SCOPE
48 struct alignas(ARCH_CACHE_LINE_SIZE*2) Node {
63 using iterator_category = std::forward_iterator_tag;
67 using difference_type = ptrdiff_t;
71 pointer operator->() {
72 return _node ? &_node->value :
nullptr;
75 reference operator*() {
90 bool operator !=(
const iterator& other)
const {
91 return _node != other._node;
94 bool operator ==(
const iterator& other)
const {
95 return _node == other._node;
99 explicit iterator(Node* node) : _node(node) {}
110 Node* curNode = _head.load(std::memory_order_acquire);
112 Node* nodeToDelete = curNode;
113 curNode = curNode->next;
114 _alloc.destroy(nodeToDelete);
115 _alloc.deallocate(nodeToDelete, 1);
125 iterator begin() {
return iterator(_head.load(std::memory_order_acquire)); }
126 iterator end() {
return iterator(); }
132 Node* newNode = _alloc.allocate(1);
133 _alloc.construct(newNode);
137 newNode->next = _head.load(std::memory_order_relaxed);
138 }
while (!_head.compare_exchange_weak(newNode->next, newNode));
143 std::atomic<Node*> _head;
144 tbb::cache_aligned_allocator<Node> _alloc;
147PXR_NAMESPACE_CLOSE_SCOPE
Provide architecture-specific memory-alignment information.
This class provides forward iterator support to iterate over all the items.
This class supports thread safe insertion and iteration over a list of items.
TraceConcurrentList()
Constructor.
iterator Insert()
Inserts an item at the beginning of the list and returns an iterator to the newly created item.
~TraceConcurrentList()
Destructor.