예제 #1
0
        unsafe public void Enqueue(T entry)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.CheckWriteAndThrow(m_Safety);
#endif

            byte *writeBlock = NativeQueueData.AllocateWriteBlockMT <T>(m_Buffer, m_QueuePool, 0);
            UnsafeUtility.WriteArrayElement(writeBlock + UnsafeUtility.SizeOf <NativeQueueBlockHeader>(), ((NativeQueueBlockHeader *)writeBlock)->itemsInBlock, entry);
            ++((NativeQueueBlockHeader *)writeBlock)->itemsInBlock;
        }
        public void Dispose()
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
#if UNITY_2018_3_OR_NEWER
            DisposeSentinel.Dispose(ref m_Safety, ref m_DisposeSentinel);
#else
            DisposeSentinel.Dispose(m_Safety, ref m_DisposeSentinel);
#endif
#endif

            NativeQueueData.DeallocateQueue(m_Buffer, m_QueuePool, m_AllocatorLabel);
            m_Buffer = null;
        }
예제 #3
0
        /// <summary>
        /// Constructs a new queue with type of memory allocation.
        /// </summary>
        /// <param name="allocator">A member of the
        /// [Unity.Collections.Allocator](https://docs.unity3d.com/ScriptReference/Unity.Collections.Allocator.html) enumeration.</param>
        public NativeQueue(Allocator allocator)
        {
            CollectionHelper.CheckIsUnmanaged <T>();

            m_QueuePool      = NativeQueueBlockPool.QueueBlockPool;
            m_AllocatorLabel = allocator;

            NativeQueueData.AllocateQueue <T>(allocator, out m_Buffer);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            DisposeSentinel.Create(out m_Safety, out m_DisposeSentinel, 0, allocator);
#endif
        }
예제 #4
0
        public unsafe NativeQueue(Allocator label)
        {
            m_QueuePool = NativeQueueBlockPool.QueueBlockPool;
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (!UnsafeUtility.IsBlittable <T>())
            {
                throw new ArgumentException(string.Format("{0} used in NativeQueue<{0}> must be blittable", typeof(T)));
            }
#endif
            m_AllocatorLabel = label;

            NativeQueueData.AllocateQueue <T>(label, out m_Buffer);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            DisposeSentinel.Create(out m_Safety, out m_DisposeSentinel, 0);
#endif
        }
예제 #5
0
        unsafe public bool TryDequeue(out T item)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.CheckWriteAndThrow(m_Safety);
#endif
            NativeQueueBlockHeader *firstBlock = NativeQueueData.GetFirstBlock(m_Buffer, m_QueuePool);

            if (firstBlock == null)
            {
                item = default(T);
                return(false);
            }

            var currentRead = m_Buffer->m_CurrentRead++;
            item = UnsafeUtility.ReadArrayElement <T>(firstBlock + 1, currentRead);

            NativeQueueData.Release(firstBlock, m_QueuePool);

            return(true);
        }
예제 #6
0
 public void Dispose()
 {
     NativeQueueData.DeallocateQueue(m_Buffer, m_QueuePool, m_AllocatorLabel);
 }
예제 #7
0
 void Deallocate()
 {
     NativeQueueData.DeallocateQueue(m_Buffer, m_QueuePool, m_AllocatorLabel);
     m_Buffer = null;
 }