predict method of l4
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace Nitload.Common.HighPerformance.Memory
|
||||
{
|
||||
@@ -27,10 +28,38 @@ namespace Nitload.Common.HighPerformance.Memory
|
||||
|
||||
internal const uint MaxBufferSize = 0xFFFFFFFF - 64U;
|
||||
|
||||
[FieldOffset(16)] internal AllocationState State;
|
||||
[FieldOffset(31)] internal AllocationState State;
|
||||
|
||||
public static uint SizeOf { get; } = (uint)Unsafe.SizeOf<CacheLineMetadata>();
|
||||
|
||||
/// <summary>
|
||||
/// only available in L4.Predict()
|
||||
/// </summary>
|
||||
public void CheckCount()
|
||||
{
|
||||
uint count = Volatile.Read(ref ConsumeCount);
|
||||
if (ushort.MaxValue < count)
|
||||
{
|
||||
uint delta = unchecked(0u - count);
|
||||
_ = Interlocked.Add(ref ConsumeCount, delta);
|
||||
_ = Interlocked.Add(ref PredictCount, delta);
|
||||
}
|
||||
}
|
||||
|
||||
public void IncreaseConsumeCount()
|
||||
{
|
||||
unchecked {
|
||||
_ = Interlocked.Increment(ref ConsumeCount);
|
||||
}
|
||||
}
|
||||
|
||||
public void IncreasePredictCount()
|
||||
{
|
||||
unchecked {
|
||||
_ = Interlocked.Increment(ref PredictCount);
|
||||
}
|
||||
}
|
||||
|
||||
#region tlsf linked list
|
||||
|
||||
[FieldOffset(0)] public short NextLevel;
|
||||
@@ -42,8 +71,15 @@ namespace Nitload.Common.HighPerformance.Memory
|
||||
|
||||
#region buffer
|
||||
|
||||
[FieldOffset(8)] public uint PositionMask;
|
||||
[FieldOffset(12)] public uint SizeMask;
|
||||
[FieldOffset(8)] public ulong Position;
|
||||
[FieldOffset(16)] public uint SizeMask;
|
||||
|
||||
#endregion
|
||||
|
||||
#region count
|
||||
|
||||
[FieldOffset(20)] public uint PredictCount;
|
||||
[FieldOffset(24)] public uint ConsumeCount;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user