Liam пре 3 година
родитељ
комит
282cd3e5fe
1 измењених фајлова са 17 додато и 10 уклоњено
  1. 17 10
      src/core/hle/kernel/k_slab_heap.h

+ 17 - 10
src/core/hle/kernel/k_slab_heap.h

@@ -8,6 +8,7 @@
 #include "common/assert.h"
 #include "common/assert.h"
 #include "common/common_funcs.h"
 #include "common/common_funcs.h"
 #include "common/common_types.h"
 #include "common/common_types.h"
+#include "common/spin_lock.h"
 
 
 namespace Kernel {
 namespace Kernel {
 
 
@@ -36,28 +37,34 @@ public:
     }
     }
 
 
     void* Allocate() {
     void* Allocate() {
-        Node* ret = m_head.load();
+        // KScopedInterruptDisable di;
 
 
-        do {
-            if (ret == nullptr) {
-                break;
-            }
-        } while (!m_head.compare_exchange_weak(ret, ret->next));
+        m_lock.lock();
+
+        Node* ret = m_head;
+        if (ret != nullptr) [[likely]] {
+            m_head = ret->next;
+        }
 
 
+        m_lock.unlock();
         return ret;
         return ret;
     }
     }
 
 
     void Free(void* obj) {
     void Free(void* obj) {
+        // KScopedInterruptDisable di;
+
+        m_lock.lock();
+
         Node* node = static_cast<Node*>(obj);
         Node* node = static_cast<Node*>(obj);
+        node->next = m_head;
+        m_head = node;
 
 
-        Node* cur_head = m_head.load();
-        do {
-            node->next = cur_head;
-        } while (!m_head.compare_exchange_weak(cur_head, node));
+        m_lock.unlock();
     }
     }
 
 
 private:
 private:
     std::atomic<Node*> m_head{};
     std::atomic<Node*> m_head{};
+    Common::SpinLock m_lock;
 };
 };
 
 
 } // namespace impl
 } // namespace impl