private bool TryEnqueue(IList <T> items, out bool full) { full = false; ConcurrentBatchQueue <T> .Entity entity = this.m_Entity; T[] array = entity.Array; int count1 = entity.Count; int count2 = items.Count; int num = count1 + count2; if (num > array.Length) { full = true; return(false); } if (entity != this.m_Entity || Interlocked.CompareExchange(ref entity.Count, num, count1) != count1) { return(false); } foreach (T obj in (IEnumerable <T>)items) { array[count1++] = obj; } return(true); }
public ConcurrentBatchQueue(T[] array, Func <T, bool> nullValidator) { this.m_Entity = new ConcurrentBatchQueue <T> .Entity(); this.m_Entity.Array = array; this.m_BackEntity = new ConcurrentBatchQueue <T> .Entity(); this.m_BackEntity.Array = new T[array.Length]; this.m_NullValidator = nullValidator; }
private bool TryEnqueue(T item, out bool full) { full = false; this.EnsureNotRebuild(); ConcurrentBatchQueue <T> .Entity entity = this.m_Entity; T[] array = entity.Array; int count = entity.Count; if (count >= array.Length) { full = true; return(false); } if (entity != this.m_Entity || Interlocked.CompareExchange(ref entity.Count, count + 1, count) != count) { return(false); } array[count] = item; return(true); }
public bool TryDequeue(IList <T> outputItems) { ConcurrentBatchQueue <T> .Entity entity = this.m_Entity; if (entity.Count <= 0) { return(false); } Interlocked.Exchange <ConcurrentBatchQueue <T> .Entity>(ref this.m_Entity, this.m_BackEntity); Thread.SpinWait(1); int count = entity.Count; T[] array = entity.Array; int index = 0; while (true) { for (T t = array[index]; this.m_NullValidator(t); t = array[index]) { Thread.SpinWait(1); } outputItems.Add(array[index]); array[index] = ConcurrentBatchQueue <T> .m_Null; if (entity.Count > index + 1) { ++index; } else { break; } } this.m_BackEntity = entity; this.m_BackEntity.Count = 0; return(true); }