Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
        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;
            }
        }
Esempio n. 5
0
 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;
     }
 }
Esempio n. 6
0
        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;
                }
            }
        }