yuzu-emu
/
yuzu
Archived
1
0
Fork 0

hle: kernel: KAutoObjectWithListContainer: Use boost::instrusive::rbtree.

- Fixes some crashes introduced by our common intrusive red/black tree impl.
This commit is contained in:
bunnei 2021-06-06 15:39:11 -07:00
parent 27ce97fd42
commit 6119836795
11 changed files with 26 additions and 22 deletions

View File

@ -7,10 +7,11 @@
#include <atomic> #include <atomic>
#include <string> #include <string>
#include <boost/intrusive/rbtree.hpp>
#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/intrusive_red_black_tree.h"
#include "core/hle/kernel/k_class_token.h" #include "core/hle/kernel/k_class_token.h"
namespace Kernel { namespace Kernel {
@ -175,7 +176,7 @@ private:
class KAutoObjectWithListContainer; class KAutoObjectWithListContainer;
class KAutoObjectWithList : public KAutoObject { class KAutoObjectWithList : public KAutoObject, public boost::intrusive::set_base_hook<> {
public: public:
explicit KAutoObjectWithList(KernelCore& kernel_) : KAutoObject(kernel_) {} explicit KAutoObjectWithList(KernelCore& kernel_) : KAutoObject(kernel_) {}
@ -192,6 +193,10 @@ public:
} }
} }
friend bool operator<(const KAutoObjectWithList& left, const KAutoObjectWithList& right) {
return &left < &right;
}
public: public:
virtual u64 GetId() const { virtual u64 GetId() const {
return reinterpret_cast<u64>(this); return reinterpret_cast<u64>(this);
@ -203,8 +208,6 @@ public:
private: private:
friend class KAutoObjectWithListContainer; friend class KAutoObjectWithListContainer;
Common::IntrusiveRedBlackTreeNode list_node;
}; };
template <typename T> template <typename T>

View File

@ -9,13 +9,13 @@ namespace Kernel {
void KAutoObjectWithListContainer::Register(KAutoObjectWithList* obj) { void KAutoObjectWithListContainer::Register(KAutoObjectWithList* obj) {
KScopedLightLock lk(m_lock); KScopedLightLock lk(m_lock);
m_object_list.insert(*obj); m_object_list.insert_unique(*obj);
} }
void KAutoObjectWithListContainer::Unregister(KAutoObjectWithList* obj) { void KAutoObjectWithListContainer::Unregister(KAutoObjectWithList* obj) {
KScopedLightLock lk(m_lock); KScopedLightLock lk(m_lock);
m_object_list.erase(m_object_list.iterator_to(*obj)); m_object_list.erase(*obj);
} }
size_t KAutoObjectWithListContainer::GetOwnedCount(KProcess* owner) { size_t KAutoObjectWithListContainer::GetOwnedCount(KProcess* owner) {

View File

@ -6,6 +6,8 @@
#include <atomic> #include <atomic>
#include <boost/intrusive/rbtree.hpp>
#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"
@ -23,8 +25,7 @@ class KAutoObjectWithListContainer {
YUZU_NON_MOVEABLE(KAutoObjectWithListContainer); YUZU_NON_MOVEABLE(KAutoObjectWithListContainer);
public: public:
using ListType = Common::IntrusiveRedBlackTreeMemberTraits< using ListType = boost::intrusive::rbtree<KAutoObjectWithList>;
&KAutoObjectWithList::list_node>::TreeType<KAutoObjectWithList>;
public: public:
class ListAccessor : public KScopedLightLock { class ListAccessor : public KScopedLightLock {

View File

@ -16,11 +16,11 @@ namespace Kernel {
KClientPort::KClientPort(KernelCore& kernel_) : KSynchronizationObject{kernel_} {} KClientPort::KClientPort(KernelCore& kernel_) : KSynchronizationObject{kernel_} {}
KClientPort::~KClientPort() = default; KClientPort::~KClientPort() = default;
void KClientPort::Initialize(KPort* parent_, s32 max_sessions_, std::string&& name_) { void KClientPort::Initialize(KPort* parent_port_, s32 max_sessions_, std::string&& name_) {
// Set member variables. // Set member variables.
num_sessions = 0; num_sessions = 0;
peak_sessions = 0; peak_sessions = 0;
parent = parent_; parent = parent_port_;
max_sessions = max_sessions_; max_sessions = max_sessions_;
name = std::move(name_); name = std::move(name_);
} }

View File

@ -36,9 +36,9 @@ public:
explicit KClientSession(KernelCore& kernel_); explicit KClientSession(KernelCore& kernel_);
~KClientSession() override; ~KClientSession() override;
void Initialize(KSession* parent_, std::string&& name_) { void Initialize(KSession* parent_session_, std::string&& name_) {
// Set member variables. // Set member variables.
parent = parent_; parent = parent_session_;
name = std::move(name_); name = std::move(name_);
} }

View File

@ -21,9 +21,9 @@ public:
explicit KReadableEvent(KernelCore& kernel_); explicit KReadableEvent(KernelCore& kernel_);
~KReadableEvent() override; ~KReadableEvent() override;
void Initialize(KEvent* parent_, std::string&& name_) { void Initialize(KEvent* parent_event_, std::string&& name_) {
is_signaled = false; is_signaled = false;
parent = parent_; parent = parent_event_;
name = std::move(name_); name = std::move(name_);
} }

View File

@ -17,9 +17,9 @@ namespace Kernel {
KServerPort::KServerPort(KernelCore& kernel_) : KSynchronizationObject{kernel_} {} KServerPort::KServerPort(KernelCore& kernel_) : KSynchronizationObject{kernel_} {}
KServerPort::~KServerPort() = default; KServerPort::~KServerPort() = default;
void KServerPort::Initialize(KPort* parent_, std::string&& name_) { void KServerPort::Initialize(KPort* parent_port_, std::string&& name_) {
// Set member variables. // Set member variables.
parent = parent_; parent = parent_port_;
name = std::move(name_); name = std::move(name_);
} }

View File

@ -29,7 +29,7 @@ public:
explicit KServerPort(KernelCore& kernel_); explicit KServerPort(KernelCore& kernel_);
~KServerPort() override; ~KServerPort() override;
void Initialize(KPort* parent_, std::string&& name_); void Initialize(KPort* parent_port_, std::string&& name_);
/// Whether or not this server port has an HLE handler available. /// Whether or not this server port has an HLE handler available.
bool HasSessionRequestHandler() const { bool HasSessionRequestHandler() const {

View File

@ -29,10 +29,10 @@ KServerSession::KServerSession(KernelCore& kernel_) : KSynchronizationObject{ker
KServerSession::~KServerSession() {} KServerSession::~KServerSession() {}
void KServerSession::Initialize(KSession* parent_, std::string&& name_, void KServerSession::Initialize(KSession* parent_session_, std::string&& name_,
std::shared_ptr<SessionRequestManager> manager_) { std::shared_ptr<SessionRequestManager> manager_) {
// Set member variables. // Set member variables.
parent = parent_; parent = parent_session_;
name = std::move(name_); name = std::move(name_);
if (manager_) { if (manager_) {

View File

@ -47,7 +47,7 @@ public:
void Destroy() override; void Destroy() override;
void Initialize(KSession* parent_, std::string&& name_, void Initialize(KSession* parent_session_, std::string&& name_,
std::shared_ptr<SessionRequestManager> manager_); std::shared_ptr<SessionRequestManager> manager_);
KSession* GetParent() { KSession* GetParent() {

View File

@ -13,8 +13,8 @@ KWritableEvent::KWritableEvent(KernelCore& kernel_)
KWritableEvent::~KWritableEvent() = default; KWritableEvent::~KWritableEvent() = default;
void KWritableEvent::Initialize(KEvent* parent_, std::string&& name_) { void KWritableEvent::Initialize(KEvent* parent_event_, std::string&& name_) {
parent = parent_; parent = parent_event_;
name = std::move(name_); name = std::move(name_);
parent->GetReadableEvent().Open(); parent->GetReadableEvent().Open();
} }