clear merging conflict
This commit is contained in:
@@ -91,8 +91,6 @@ namespace StgSharp.HighPerformance.Memory
|
||||
|
||||
RemoveFromBucket(originLevel, segment, (BucketNode*)entry->Position);
|
||||
|
||||
SetEntryState(entry, EntryState.Merging);
|
||||
|
||||
while (originLevel >= entry->Level)
|
||||
{
|
||||
originLevel = entry->Level;
|
||||
@@ -101,12 +99,11 @@ namespace StgSharp.HighPerformance.Memory
|
||||
// backward merging - simplified to single attempt
|
||||
ulong p = entry->PreviousNear;
|
||||
Entry* prev = (Entry*)p;
|
||||
if (prev != null ||
|
||||
prev != _spareMemory ||
|
||||
GetEntryState(prev) == EntryState.Empty ||
|
||||
if (prev == null ||
|
||||
prev == _spareMemory ||
|
||||
!AssertBackwardBoundary(entry->Position, prev, originLevel) ||
|
||||
IsAdjacentTo(entry, prev) ||
|
||||
entry->Level == prev->Level ||
|
||||
entry->Level != prev->Level ||
|
||||
!TryRemoveFromBucket(originLevel, DetermineSegmentIndex(prev->Size, originLevel), (BucketNode*)prev->Position))
|
||||
{
|
||||
break;
|
||||
@@ -130,12 +127,11 @@ namespace StgSharp.HighPerformance.Memory
|
||||
// forward merging - simplified to single attempt
|
||||
ulong n = entry->NextNear;
|
||||
Entry* next = (Entry*)n;
|
||||
if (next != null ||
|
||||
next != _spareMemory ||
|
||||
GetEntryState(next) == EntryState.Empty ||
|
||||
if (next == null ||
|
||||
next == _spareMemory ||
|
||||
!AssertForwardBoundary(entry->Position + entry->Size, next, entry->Level) ||
|
||||
IsAdjacentTo(entry, next) ||
|
||||
entry->Level == next->Level ||
|
||||
entry->Level != next->Level ||
|
||||
!TryRemoveFromBucket(originLevel, DetermineSegmentIndex(next->Size, originLevel), (BucketNode*)next->Position))
|
||||
{
|
||||
break;
|
||||
@@ -148,14 +144,12 @@ namespace StgSharp.HighPerformance.Memory
|
||||
}
|
||||
entry->NextNear = (ulong)nextNext;
|
||||
|
||||
|
||||
// Merge
|
||||
entry->Size += next->Size;
|
||||
RecycleEntry(next);
|
||||
}
|
||||
entry->Level = GetLevelFromSize(entry->Size);
|
||||
}
|
||||
SetEntryState(entry, EntryState.Empty);
|
||||
}
|
||||
|
||||
private void RecycleEntry(Entry* entry)
|
||||
@@ -164,7 +158,6 @@ namespace StgSharp.HighPerformance.Memory
|
||||
return;
|
||||
}
|
||||
|
||||
entry->State = EntryState.Empty;
|
||||
entry->PreviousNear = EmptyHandle;
|
||||
entry->NextNear = EmptyHandle;
|
||||
_entries.Free((nuint)entry);
|
||||
@@ -199,27 +192,24 @@ namespace StgSharp.HighPerformance.Memory
|
||||
/// Entry structure - streamlined version (only position and state information) Stored in
|
||||
/// external SLAB
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Explicit, Size = 32)]
|
||||
[StructLayout(LayoutKind.Explicit, Size = 36)]
|
||||
internal struct Entry
|
||||
{
|
||||
|
||||
[FieldOffset(28)] internal int Level; // Level of the block in the allocator
|
||||
[FieldOffset(20)] internal int State; // Node state (using int for atomic operations)
|
||||
[FieldOffset(24)] internal uint Size; // Block size information
|
||||
[FieldOffset(8)] internal ulong NextNear; // Position linked list: next pointer
|
||||
[FieldOffset(16)] internal ulong PreviousNear; // Position linked list: previous pointer
|
||||
[FieldOffset(32)] public EntryState State;
|
||||
[FieldOffset(0)] public nuint Position; // Memory block position
|
||||
|
||||
}
|
||||
|
||||
// 更新后的EntryState常量类 - 使用int类型
|
||||
private static class EntryState
|
||||
internal enum EntryState : uint
|
||||
{
|
||||
|
||||
public const int Allocated = 1; // Already allocated to user
|
||||
public const int Empty = 0; // Free, can be allocated
|
||||
public const int Merging = 3; // Currently being merged
|
||||
public const int ThreadOccupied = 2; // Occupied by thread (being operated on)
|
||||
Empty,
|
||||
Allocated
|
||||
|
||||
}
|
||||
|
||||
@@ -237,56 +227,6 @@ namespace StgSharp.HighPerformance.Memory
|
||||
return entry == null;
|
||||
}
|
||||
|
||||
// Entry 状态操作
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static bool TrySetEntryState(Entry* entry, int expectedState, int newState)
|
||||
{
|
||||
if (entry != null && entry->State == expectedState)
|
||||
{
|
||||
entry->State = newState;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static int GetEntryState(Entry* entry)
|
||||
{
|
||||
return entry != null ? entry->State : 0;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void SetEntryState(Entry* entry, int newState)
|
||||
{
|
||||
if (entry != null) {
|
||||
entry->State = newState;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static bool IsEntryEmpty(Entry* entry)
|
||||
{
|
||||
return GetEntryState(entry) == EntryState.Empty;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static bool IsEntryAllocated(Entry* entry)
|
||||
{
|
||||
return GetEntryState(entry) == EntryState.Allocated;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static bool IsEntryThreadOccupied(Entry* entry)
|
||||
{
|
||||
return GetEntryState(entry) == EntryState.ThreadOccupied;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static bool IsEntryMerging(Entry* entry)
|
||||
{
|
||||
return GetEntryState(entry) == EntryState.Merging;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user