mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-07-04 23:31:19 +01:00
Merge pull request #9083 from liamwhite/take-a-chance-on-me
kernel: fix slab heap ABA
This commit is contained in:
commit
925fb63478
1 changed files with 18 additions and 11 deletions
|
@ -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 {
|
m_lock.lock();
|
||||||
if (ret == nullptr) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (!m_head.compare_exchange_weak(ret, ret->next));
|
|
||||||
|
|
||||||
|
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) {
|
||||||
Node* node = static_cast<Node*>(obj);
|
// KScopedInterruptDisable di;
|
||||||
|
|
||||||
Node* cur_head = m_head.load();
|
m_lock.lock();
|
||||||
do {
|
|
||||||
node->next = cur_head;
|
Node* node = static_cast<Node*>(obj);
|
||||||
} while (!m_head.compare_exchange_weak(cur_head, node));
|
node->next = m_head;
|
||||||
|
m_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
|
||||||
|
|
Loading…
Reference in a new issue