8#ifndef PXR_BASE_TRACE_CONCURRENT_LIST_H
9#define PXR_BASE_TRACE_CONCURRENT_LIST_H
15#include <tbb/cache_aligned_allocator.h>
20PXR_NAMESPACE_OPEN_SCOPE
31 struct alignas(ARCH_CACHE_LINE_SIZE*2) Node {
46 using iterator_category = std::forward_iterator_tag;
50 using difference_type = ptrdiff_t;
54 pointer operator->() {
55 return _node ? &_node->value :
nullptr;
58 reference operator*() {
73 bool operator !=(
const iterator& other)
const {
74 return _node != other._node;
77 bool operator ==(
const iterator& other)
const {
78 return _node == other._node;
82 explicit iterator(Node* node) : _node(node) {}
93 Node* curNode = _head.load(std::memory_order_acquire);
95 Node* nodeToDelete = curNode;
96 curNode = curNode->next;
97 nodeToDelete->~Node();
98 _alloc.deallocate(nodeToDelete, 1);
108 iterator begin() {
return iterator(_head.load(std::memory_order_acquire)); }
109 iterator end() {
return iterator(); }
115 Node* newNode = _alloc.allocate(1);
120 newNode->next = _head.load(std::memory_order_relaxed);
121 }
while (!_head.compare_exchange_weak(newNode->next, newNode));
126 std::atomic<Node*> _head;
127 tbb::cache_aligned_allocator<Node> _alloc;
130PXR_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.