Skip to content

Commit

Permalink
Disable interrupts in Heap.Collect, not free
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinbreiz committed Feb 9, 2022
1 parent 64362cb commit 3fdb336
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions source/Cosmos.Core/Memory/Heap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ public static uint SafeAlloc(uint aSize)
/// </exception>
public static void Free(void* aPtr)
{
CPU.DisableInterrupts();

//TODO find a better way to remove the double look up here for GetPageType and then again in the
// .Free methods which actually free the entries in the RAT.
//Debugger.DoSendNumber(0x77);
Expand All @@ -105,8 +103,6 @@ public static void Free(void* aPtr)
default:
throw new Exception("Heap item not found in RAT.");
}

CPU.EnableInterrupts();
}

/// <summary>
Expand All @@ -115,6 +111,9 @@ public static void Free(void* aPtr)
/// <returns>Number of objects freed</returns>
public static int Collect()
{
//Disable interrupts: Prevent CPU exception when allocation is called from interrupt code
CPU.DisableInterrupts();

// Mark and sweep objects from roots
// 1. Check if a page is in use if medium/large mark and sweep object
// 2. Go throught the SMT table for small objects and go through pages by size
Expand Down Expand Up @@ -234,6 +233,9 @@ public static int Collect()

rootSMTPtr = rootSMTPtr->LargerSize;
}

//Enable interrupts back
CPU.EnableInterrupts();

return freed;
}
Expand Down

0 comments on commit 3fdb336

Please sign in to comment.