From e11cf31b051b7aff82c248e90e51bc0b1fdcd01a Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 3 Dec 2021 11:44:53 +0100 Subject: [PATCH] Revert "Replace the Spinlock with a Mutex, flush the heap header" This reverts commit 60d000a27717e52716a725d6fe785344bbb984f4. --- source/memory_mapping.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/source/memory_mapping.cpp b/source/memory_mapping.cpp index 68b7cca..52ac7e2 100644 --- a/source/memory_mapping.cpp +++ b/source/memory_mapping.cpp @@ -11,11 +11,9 @@ #include "CThread.h" #include #include -#include #include -OSMutex allocFreeMutex; - +OSSpinLock allocFreeSpinlock; // #define DEBUG_FUNCTION_LINE(x,...) @@ -384,11 +382,10 @@ void MemoryMapping_setupMemoryMapping() { //readTestValuesFromMemory(); //runOnAllCores(writeSegmentRegister,&srTableCpy); - OSInitMutex(&allocFreeMutex); } void *MemoryMapping_allocEx(uint32_t size, int32_t align, bool videoOnly) { - OSLockMutex(&allocFreeMutex); + OSUninterruptibleSpinLock_Acquire(&allocFreeSpinlock); void *res = nullptr; for (int32_t i = 0; /* waiting for a break */; i++) { if (mem_mapping[i].physical_addresses == nullptr) { @@ -403,8 +400,6 @@ void *MemoryMapping_allocEx(uint32_t size, int32_t align, bool videoOnly) { continue; } - DCFlushRange(heap, sizeof(MEMExpHeap)); - res = MEMAllocFromExpHeapEx(heapHandle, size, align); auto cur = heap->usedList.head; while (cur != nullptr) { @@ -420,7 +415,7 @@ void *MemoryMapping_allocEx(uint32_t size, int32_t align, bool videoOnly) { break; } } - OSUnlockMutex(&allocFreeMutex); + OSUninterruptibleSpinLock_Release(&allocFreeSpinlock); return res; } @@ -436,7 +431,7 @@ void MemoryMapping_free(void *ptr) { if (ptr == nullptr) { return; } - OSLockMutex(&allocFreeMutex); + OSUninterruptibleSpinLock_Acquire(&allocFreeSpinlock); auto ptr_val = (uint32_t) ptr; for (int32_t i = 0; /* waiting for a break */; i++) { if (mem_mapping[i].physical_addresses == nullptr) { @@ -447,7 +442,6 @@ void MemoryMapping_free(void *ptr) { auto *heap = (MEMExpHeap *) heapHandle; MEMFreeToExpHeap((MEMHeapHandle) mem_mapping[i].effective_start_address, ptr); - DCFlushRange(heap, sizeof(MEMExpHeap)); auto cur = heap->usedList.head; while (cur != nullptr) { DCFlushRange(cur, sizeof(MEMExpHeapBlock)); @@ -461,7 +455,7 @@ void MemoryMapping_free(void *ptr) { break; } } - OSUnlockMutex(&allocFreeMutex); + OSUninterruptibleSpinLock_Release(&allocFreeSpinlock); } uint32_t MemoryMapping_MEMGetAllocatableSize() {