Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 8ae1532

Browse files
committed
ConcurrentStack -> ConcurrentQueue
ConcurrentStack allocates a ConcurrentStack<T>.Node per Push
1 parent 24d742a commit 8ae1532

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class MemoryPool2 : IDisposable
4646
/// Thread-safe collection of blocks which are currently in the pool. A slab will pre-allocate all of the block tracking objects
4747
/// and add them to this collection. When memory is requested it is taken from here first, and when it is returned it is re-added.
4848
/// </summary>
49-
private readonly ConcurrentStack<MemoryPoolBlock2> _blocks = new ConcurrentStack<MemoryPoolBlock2>();
49+
private readonly ConcurrentQueue<MemoryPoolBlock2> _blocks = new ConcurrentQueue<MemoryPoolBlock2>();
5050

5151
/// <summary>
5252
/// Thread-safe collection of slabs which have been allocated by this pool. As long as a slab is in this collection and slab.IsActive,
@@ -88,7 +88,7 @@ public MemoryPoolBlock2 Lease(int minimumSize = MaxPooledBlockLength)
8888
}
8989

9090
MemoryPoolBlock2 block;
91-
if (_blocks.TryPop(out block))
91+
if (_blocks.TryDequeue(out block))
9292
{
9393
// block successfully taken from the stack - return it
9494
return block;
@@ -145,7 +145,7 @@ private MemoryPoolBlock2 AllocateSlab()
145145
public void Return(MemoryPoolBlock2 block)
146146
{
147147
block.Reset();
148-
_blocks.Push(block);
148+
_blocks.Enqueue(block);
149149
}
150150

151151
protected virtual void Dispose(bool disposing)
@@ -158,7 +158,7 @@ protected virtual void Dispose(bool disposing)
158158
}
159159

160160
MemoryPoolBlock2 block;
161-
while (_blocks.TryPop(out block))
161+
while (_blocks.TryDequeue(out block))
162162
{
163163
// Deactivate finalizers
164164
block.Dispose();

0 commit comments

Comments
 (0)