diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/k_slab_heap.h | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/core/hle/kernel/k_slab_heap.h b/src/core/hle/kernel/k_slab_heap.h index 2b303537e..a8c77a7d4 100644 --- a/src/core/hle/kernel/k_slab_heap.h +++ b/src/core/hle/kernel/k_slab_heap.h | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include "common/assert.h" | 8 | #include "common/assert.h" |
| 9 | #include "common/common_funcs.h" | 9 | #include "common/common_funcs.h" |
| 10 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 11 | #include "common/spin_lock.h" | ||
| 11 | 12 | ||
| 12 | namespace Kernel { | 13 | namespace Kernel { |
| 13 | 14 | ||
| @@ -36,28 +37,34 @@ public: | |||
| 36 | } | 37 | } |
| 37 | 38 | ||
| 38 | void* Allocate() { | 39 | void* Allocate() { |
| 39 | Node* ret = m_head.load(); | 40 | // KScopedInterruptDisable di; |
| 40 | 41 | ||
| 41 | do { | 42 | m_lock.lock(); |
| 42 | if (ret == nullptr) { | 43 | |
| 43 | break; | 44 | Node* ret = m_head; |
| 44 | } | 45 | if (ret != nullptr) [[likely]] { |
| 45 | } while (!m_head.compare_exchange_weak(ret, ret->next)); | 46 | m_head = ret->next; |
| 47 | } | ||
| 46 | 48 | ||
| 49 | m_lock.unlock(); | ||
| 47 | return ret; | 50 | return ret; |
| 48 | } | 51 | } |
| 49 | 52 | ||
| 50 | void Free(void* obj) { | 53 | void Free(void* obj) { |
| 54 | // KScopedInterruptDisable di; | ||
| 55 | |||
| 56 | m_lock.lock(); | ||
| 57 | |||
| 51 | Node* node = static_cast<Node*>(obj); | 58 | Node* node = static_cast<Node*>(obj); |
| 59 | node->next = m_head; | ||
| 60 | m_head = node; | ||
| 52 | 61 | ||
| 53 | Node* cur_head = m_head.load(); | 62 | m_lock.unlock(); |
| 54 | do { | ||
| 55 | node->next = cur_head; | ||
| 56 | } while (!m_head.compare_exchange_weak(cur_head, node)); | ||
| 57 | } | 63 | } |
| 58 | 64 | ||
| 59 | private: | 65 | private: |
| 60 | std::atomic<Node*> m_head{}; | 66 | std::atomic<Node*> m_head{}; |
| 67 | Common::SpinLock m_lock; | ||
| 61 | }; | 68 | }; |
| 62 | 69 | ||
| 63 | } // namespace impl | 70 | } // namespace impl |