fix sever L4 errors

This commit is contained in:
Nitload
2026-03-17 00:31:52 +08:00
parent f8a879c4da
commit 98d711a3ca
4 changed files with 104 additions and 53 deletions
@@ -1,9 +1,9 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="L4.InternalOp"
// file="L4.Evict"
// Project: StgSharp
// AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved.
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -54,10 +54,17 @@ namespace StgSharp.HighPerformance.Memory
}
}
/// <summary>
///
/// </summary>
/// <param name="count">
///
/// </param>
/// <returns>
/// Count of lines not evicted
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private unsafe void Evict(
int count = 1
)
private unsafe int Evict(int count = 1)
{
int remain = count;
Vector128<byte> one = Vector128.Create((byte)0x01);
@@ -77,32 +84,30 @@ namespace StgSharp.HighPerformance.Memory
{
// EvictLine(i + index);
_ = _map.TryRemove(head->_origin, out _);
PrefetchPredict.WriteBack(head->_address, head->_profile, new ReadOnlySpan<byte>((byte*)head->_address, Unsafe.SizeOf<CacheLineData>()));
RecycleLine(index);
remain--;
}
evictMask &= evictMask - 1;
}
}
return remain;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void RecycleLine(
int id
)
private void RecycleLine(int id)
{
_idMux.Push(id);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool TryGetEmptyLine(
out int index
)
private bool TryGetEmptyLine(out int index)
{
if (_idMux.TryPop(out index)) {
return true;
}
index = _maxId;
return Interlocked.Increment(ref _maxId) >= CacheLineCount;
return Interlocked.Increment(ref _maxId) <= CacheLineCount;
}
}