Fixes code according to modern code style. Fixes a few expression bugs.
This commit is contained in:
parent
89eea25e5f
commit
970fd563b2
3324 changed files with 441118 additions and 433755 deletions
|
|
@ -22,77 +22,85 @@ using System.Collections.Generic;
|
|||
|
||||
namespace Server.Network
|
||||
{
|
||||
public class BufferPool
|
||||
{
|
||||
public static List<BufferPool> Pools { get; set; } = new List<BufferPool>();
|
||||
public class BufferPool
|
||||
{
|
||||
private int m_BufferSize;
|
||||
|
||||
private string m_Name;
|
||||
private Queue<byte[]> m_FreeBuffers;
|
||||
|
||||
private int m_InitialCapacity;
|
||||
private int m_BufferSize;
|
||||
private int m_InitialCapacity;
|
||||
|
||||
private int m_Misses;
|
||||
private int m_Misses;
|
||||
|
||||
private Queue<byte[]> m_FreeBuffers;
|
||||
private string m_Name;
|
||||
|
||||
public void GetInfo( out string name, out int freeCount, out int initialCapacity, out int currentCapacity, out int bufferSize, out int misses )
|
||||
{
|
||||
lock ( this )
|
||||
{
|
||||
name = m_Name;
|
||||
freeCount = m_FreeBuffers.Count;
|
||||
initialCapacity = m_InitialCapacity;
|
||||
currentCapacity = m_InitialCapacity * (1 + m_Misses);
|
||||
bufferSize = m_BufferSize;
|
||||
misses = m_Misses;
|
||||
}
|
||||
}
|
||||
public BufferPool(string name, int initialCapacity, int bufferSize)
|
||||
{
|
||||
m_Name = name;
|
||||
|
||||
public BufferPool( string name, int initialCapacity, int bufferSize )
|
||||
{
|
||||
m_Name = name;
|
||||
m_InitialCapacity = initialCapacity;
|
||||
m_BufferSize = bufferSize;
|
||||
|
||||
m_InitialCapacity = initialCapacity;
|
||||
m_BufferSize = bufferSize;
|
||||
m_FreeBuffers = new Queue<byte[]>(initialCapacity);
|
||||
|
||||
m_FreeBuffers = new Queue<byte[]>( initialCapacity );
|
||||
for (int i = 0; i < initialCapacity; ++i)
|
||||
m_FreeBuffers.Enqueue(new byte[bufferSize]);
|
||||
|
||||
for ( int i = 0; i < initialCapacity; ++i )
|
||||
m_FreeBuffers.Enqueue( new byte[bufferSize] );
|
||||
lock (Pools)
|
||||
{
|
||||
Pools.Add(this);
|
||||
}
|
||||
}
|
||||
|
||||
lock ( Pools )
|
||||
Pools.Add( this );
|
||||
}
|
||||
public static List<BufferPool> Pools{ get; set; } = new List<BufferPool>();
|
||||
|
||||
public byte[] AcquireBuffer()
|
||||
{
|
||||
lock ( this )
|
||||
{
|
||||
if ( m_FreeBuffers.Count > 0 )
|
||||
return m_FreeBuffers.Dequeue();
|
||||
public void GetInfo(out string name, out int freeCount, out int initialCapacity, out int currentCapacity,
|
||||
out int bufferSize, out int misses)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
name = m_Name;
|
||||
freeCount = m_FreeBuffers.Count;
|
||||
initialCapacity = m_InitialCapacity;
|
||||
currentCapacity = m_InitialCapacity * (1 + m_Misses);
|
||||
bufferSize = m_BufferSize;
|
||||
misses = m_Misses;
|
||||
}
|
||||
}
|
||||
|
||||
++m_Misses;
|
||||
public byte[] AcquireBuffer()
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
if (m_FreeBuffers.Count > 0)
|
||||
return m_FreeBuffers.Dequeue();
|
||||
|
||||
for ( int i = 0; i < m_InitialCapacity; ++i )
|
||||
m_FreeBuffers.Enqueue( new byte[m_BufferSize] );
|
||||
++m_Misses;
|
||||
|
||||
return m_FreeBuffers.Dequeue();
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < m_InitialCapacity; ++i)
|
||||
m_FreeBuffers.Enqueue(new byte[m_BufferSize]);
|
||||
|
||||
public void ReleaseBuffer( byte[] buffer )
|
||||
{
|
||||
if ( buffer == null )
|
||||
return;
|
||||
return m_FreeBuffers.Dequeue();
|
||||
}
|
||||
}
|
||||
|
||||
lock ( this )
|
||||
m_FreeBuffers.Enqueue( buffer );
|
||||
}
|
||||
public void ReleaseBuffer(byte[] buffer)
|
||||
{
|
||||
if (buffer == null)
|
||||
return;
|
||||
|
||||
public void Free()
|
||||
{
|
||||
lock ( Pools )
|
||||
Pools.Remove( this );
|
||||
}
|
||||
}
|
||||
lock (this)
|
||||
{
|
||||
m_FreeBuffers.Enqueue(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public void Free()
|
||||
{
|
||||
lock (Pools)
|
||||
{
|
||||
Pools.Remove(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue