remove a bunch of locks
This commit is contained in:
parent
b3bf62b391
commit
d7b8664062
13 changed files with 126 additions and 143 deletions
25
tanks-backend/TanksServer/Interactivity/BufferPool.cs
Normal file
25
tanks-backend/TanksServer/Interactivity/BufferPool.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using System.Buffers;
|
||||
|
||||
namespace TanksServer.Interactivity;
|
||||
|
||||
internal sealed class BufferPool: MemoryPool<byte>
|
||||
{
|
||||
private readonly MemoryPool<byte> _actualPool = Shared;
|
||||
|
||||
public override int MaxBufferSize => int.MaxValue;
|
||||
|
||||
protected override void Dispose(bool disposing) {}
|
||||
|
||||
public override IMemoryOwner<byte> Rent(int minBufferSize = -1)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(minBufferSize, 1);
|
||||
return new BufferPoolMemoryOwner(_actualPool.Rent(minBufferSize), minBufferSize);
|
||||
}
|
||||
|
||||
private sealed class BufferPoolMemoryOwner(IMemoryOwner<byte> actualOwner, int wantedSize): IMemoryOwner<byte>
|
||||
{
|
||||
public Memory<byte> Memory { get; } = actualOwner.Memory[..wantedSize];
|
||||
|
||||
public void Dispose() => actualOwner.Dispose();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue