L4 is now a burden
This commit is contained in:
@@ -119,5 +119,37 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public unsafe ref struct Handle : IDisposable
|
||||||
|
{
|
||||||
|
|
||||||
|
private CacheLineMetadata* _head;
|
||||||
|
private nuint _handle;
|
||||||
|
|
||||||
|
private Handle(
|
||||||
|
nuint handle,
|
||||||
|
CacheLineMetadata* cacheRefCount
|
||||||
|
)
|
||||||
|
{
|
||||||
|
_handle = handle;
|
||||||
|
_head = cacheRefCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Obsolete("You should not create a CacheLineHandle instance outside a L4", true)]
|
||||||
|
public Handle() { }
|
||||||
|
|
||||||
|
public readonly nuint Address => _handle;
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (_handle == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_handle = 0;
|
||||||
|
_ = Interlocked.Decrement(ref _head->RefCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,16 +33,11 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
public unsafe partial class L4
|
public unsafe partial class L4
|
||||||
{
|
{
|
||||||
|
|
||||||
public const int MaxActivateCacheLineCount = 1024;
|
|
||||||
|
|
||||||
private partial void Prefetch()
|
private partial void Prefetch()
|
||||||
{
|
{
|
||||||
if (CurrentPredict is null) {
|
if (CurrentPredict is null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_activeCount > MaxActivateCacheLineCount) {
|
|
||||||
throw new OverflowException("Too many activated cache line in external reference.");
|
|
||||||
}
|
|
||||||
IL4Predict predict = CurrentPredict;
|
IL4Predict predict = CurrentPredict;
|
||||||
int predictIndex = CurrentPredictIndex;
|
int predictIndex = CurrentPredictIndex;
|
||||||
Span<CacheLineDescription> span = new(_prediction, PredictionCount);
|
Span<CacheLineDescription> span = new(_prediction, PredictionCount);
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
private readonly CacheLineDescription* _prediction;
|
private readonly CacheLineDescription* _prediction;
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
private bool _exhausted;
|
private bool _exhausted;
|
||||||
private int _activeCount;
|
|
||||||
|
|
||||||
private int _aheadCount;
|
private int _aheadCount;
|
||||||
|
|
||||||
@@ -123,7 +122,7 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void ContinueOnce(
|
public void ContinueOnce(
|
||||||
L4CacheLine line
|
Handle line
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (line.Address > 0) {
|
if (line.Address > 0) {
|
||||||
@@ -157,8 +156,8 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public L4CacheLine Map(
|
public Handle Map(
|
||||||
ref CacheLineDescription prediction
|
ref CacheLineDescription prediction
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if ((_aheadCount < PredictionLeastAhead) && !_exhausted)
|
if ((_aheadCount < PredictionLeastAhead) && !_exhausted)
|
||||||
@@ -188,10 +187,9 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
if (Interlocked.Increment(ref entry->RefCount) > 0)
|
if (Interlocked.Increment(ref entry->RefCount) > 0)
|
||||||
{
|
{
|
||||||
(*_predictCount)[entry->Id] = 0;
|
(*_predictCount)[entry->Id] = 0;
|
||||||
_ = Interlocked.Increment(ref _activeCount);
|
|
||||||
_ = Interlocked.Decrement(ref _aheadCount);
|
_ = Interlocked.Decrement(ref _aheadCount);
|
||||||
_ = Interlocked.Decrement(ref (*_mapCount)[entry->Id]);
|
_ = Interlocked.Decrement(ref (*_mapCount)[entry->Id]);
|
||||||
return new L4CacheLine((nuint)entry->Position, ref _activeCount, ref entry->RefCount);
|
return new Handle((nuint)entry->Position, ref entry->RefCount);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
_ = Interlocked.Decrement(ref entry->RefCount);
|
_ = Interlocked.Decrement(ref entry->RefCount);
|
||||||
@@ -204,39 +202,4 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
private partial void Prefetch();
|
private partial void Prefetch();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ref struct L4CacheLine : IDisposable
|
|
||||||
{
|
|
||||||
|
|
||||||
private ref int _activeCount;
|
|
||||||
private ref int _refCount;
|
|
||||||
private nuint _handle;
|
|
||||||
|
|
||||||
internal L4CacheLine(
|
|
||||||
nuint handle,
|
|
||||||
ref int activeCount,
|
|
||||||
ref int cacheRefCount
|
|
||||||
)
|
|
||||||
{
|
|
||||||
_handle = handle;
|
|
||||||
_refCount = ref cacheRefCount;
|
|
||||||
_activeCount = ref activeCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Obsolete("You should not create a CacheLineHandle instance outside a L4", true)]
|
|
||||||
public L4CacheLine() { }
|
|
||||||
|
|
||||||
public readonly nuint Address => _handle;
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
if (_handle == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_handle = 0;
|
|
||||||
_ = Interlocked.Decrement(ref _activeCount);
|
|
||||||
_ = Interlocked.Decrement(ref _refCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user