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