Mercurial > pub > ImplabNet
diff Implab/Parallels/AsyncQueue.cs @ 125:f803565868a4 v2
improved performance of promises
author | cin |
---|---|
date | Thu, 15 Jan 2015 12:09:20 +0300 |
parents | a336cb13c6a9 |
children | d86da8d2d4c3 |
line wrap: on
line diff
--- a/Implab/Parallels/AsyncQueue.cs Thu Jan 15 02:43:14 2015 +0300 +++ b/Implab/Parallels/AsyncQueue.cs Thu Jan 15 12:09:20 2015 +0300 @@ -147,15 +147,9 @@ public const int DEFAULT_CHUNK_SIZE = 32; public const int MAX_CHUNK_SIZE = 262144; - readonly int m_chunkSize = DEFAULT_CHUNK_SIZE; - Chunk m_first; Chunk m_last; - public AsyncQueue() { - m_last = m_first = new Chunk(m_chunkSize); - } - /// <summary> /// Adds the specified value to the queue. /// </summary> @@ -167,7 +161,7 @@ while (last == null || !last.TryEnqueue(value, out extend)) { // try to extend queue if (extend || last == null) { - var chunk = new Chunk(m_chunkSize, value); + var chunk = new Chunk(DEFAULT_CHUNK_SIZE, value); if (EnqueueChunk(last, chunk)) break; // success! exit! last = m_last; @@ -215,7 +209,7 @@ var size = Math.Min(length, MAX_CHUNK_SIZE); var chunk = new Chunk( - Math.Max(size, m_chunkSize), + Math.Max(size, DEFAULT_CHUNK_SIZE), data, offset, size, @@ -404,7 +398,7 @@ public void Clear() { // start the new queue - var chunk = new Chunk(m_chunkSize); + var chunk = new Chunk(DEFAULT_CHUNK_SIZE); do { Thread.MemoryBarrier(); @@ -431,7 +425,7 @@ public T[] Drain() { // start the new queue - var chunk = new Chunk(m_chunkSize); + var chunk = new Chunk(DEFAULT_CHUNK_SIZE); do { Thread.MemoryBarrier(); @@ -458,7 +452,7 @@ T[] ReadChunks(Chunk chunk, object last) { var result = new List<T>(); - var buffer = new T[m_chunkSize]; + var buffer = new T[DEFAULT_CHUNK_SIZE]; int actual; bool recycle; while (chunk != null) {