private void AddNewPageConcurrent <T>(NodeConstantCapacity *node, ref T obj) where T : unmanaged { var newPage = NodeConstantCapacity.CreatePtr <T>(capacity, allocator); newPage->TryAddConcurrent(ref obj, capacity); AddNewPageConcurrent(node, newPage); }
private int AddNewPageConcurrent <T>(NodeConstantCapacity *node, T *values, int count) where T : unmanaged { var newPage = NodeConstantCapacity.CreatePtr <T>(capacity, allocator); var consumed = newPage->TryAddRangeConcurrent(values, count, capacity, out _); AddNewPageConcurrent(node, newPage); return(consumed); }
public UnrolledLinkedList(int capacity, int elementSize, Allocator allocator) { this.capacity = capacity; this.allocator = allocator; LastFull = null; First = (NodeConstantCapacity *)UnsafeUtility.Malloc(sizeof(NodeConstantCapacity), 4, allocator); *First = new NodeConstantCapacity(capacity, elementSize, allocator); }
private static void AddNewPageConcurrent(NodeConstantCapacity *node, NodeConstantCapacity *newPage) { var add = new IntPtr(newPage); while (IntPtr.Zero != Interlocked.CompareExchange(ref node->NextNode, add, IntPtr.Zero)) { node = node->Next; } }
private void AddToExistingPageConcurrent <T>(NodeConstantCapacity *node, ref T obj) where T : unmanaged { while (!node->TryAddConcurrent(ref obj, capacity)) { LastFull = node; var next = node->Next; if (next == null) { AddNewPageConcurrent(node, ref obj); break; } node = next; } }
public unsafe void AddRangeConcurrent <T>(T *values, int count) where T : unmanaged { NodeConstantCapacity *node = LastFull == null ? First : LastFull; while (true) { while (node->IsFull(capacity)) { LastFull = node; if (node->NextNode == IntPtr.Zero && ConsumeAndIsEnd(ref values, ref count, AddNewPageConcurrent(node, values, count))) { return; } node = node->Next; } if (ConsumeAndIsEnd(ref values, ref count, node->TryAddRangeConcurrent(values, count, capacity, out _))) { return; } } }