L4 brief ok
This commit is contained in:
@@ -73,7 +73,7 @@ namespace StgSharp.HighPerformance.Memory
|
||||
int bitPos = BitOperations.TrailingZeroCount(evictMask);
|
||||
int index = bitPos + i;
|
||||
CacheLineHead* head = &_head[index];
|
||||
if (Interlocked.CompareExchange(ref head->_refCount, -1, 0) == 0)
|
||||
if (Interlocked.CompareExchange(ref head->_refCount, int.MinValue, 0) == 0)
|
||||
{
|
||||
// EvictLine(i + index);
|
||||
_ = _map.TryRemove(head->_origin, out _);
|
||||
|
||||
@@ -82,6 +82,7 @@ namespace StgSharp.HighPerformance.Memory
|
||||
CacheLineHead* head = (CacheLineHead*)handle;
|
||||
int index = head->_id;
|
||||
(*_eviction)[index] = 0; // reset eviction counter
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -118,12 +118,16 @@ namespace StgSharp.HighPerformance.Memory
|
||||
{
|
||||
if (Interlocked.CompareExchange(ref _prefetching, 1, 0) == 0)
|
||||
{
|
||||
if (_aheadCount < PredictionLeastAhead)
|
||||
try
|
||||
{
|
||||
// do prefetch in work load now, sync
|
||||
Prefetch();
|
||||
break;
|
||||
} else
|
||||
if (_aheadCount < PredictionLeastAhead)
|
||||
{
|
||||
// do prefetch in work load now, sync
|
||||
Prefetch();
|
||||
break;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_prefetching = 0;
|
||||
}
|
||||
@@ -136,9 +140,10 @@ namespace StgSharp.HighPerformance.Memory
|
||||
{
|
||||
// cache hit
|
||||
CacheLineHead* entry = (CacheLineHead*)entryHandle;
|
||||
if (Interlocked.Increment(ref entry->_refCount) < 0)
|
||||
if (Interlocked.Increment(ref entry->_refCount) > 0)
|
||||
{
|
||||
(*_eviction)[entry->_id] = 0;
|
||||
_ = Interlocked.Increment(ref _activeCount);
|
||||
return new CacheLine(entry->_address, ref _activeCount, ref entry->_refCount);
|
||||
} else
|
||||
{
|
||||
@@ -171,8 +176,6 @@ namespace StgSharp.HighPerformance.Memory
|
||||
_handle = handle;
|
||||
_refCount = ref cacheRefCount;
|
||||
_activeCount = ref activeCount;
|
||||
_ = Interlocked.Increment(ref _activeCount);
|
||||
_ = Interlocked.Increment(ref _refCount);
|
||||
}
|
||||
|
||||
[Obsolete("You should not create a CacheLineHandle outside a L4", true)]
|
||||
|
||||
Reference in New Issue
Block a user