mirror of https://git.suyu.dev/suyu/suyu
hle: kernel: Add initial impl. of KAutoObjectWithListContainer.
This commit is contained in:
parent
b8751630e2
commit
34ce1dd7c7
|
@ -163,6 +163,8 @@ add_library(core STATIC
|
||||||
hle/kernel/k_address_space_info.h
|
hle/kernel/k_address_space_info.h
|
||||||
hle/kernel/k_auto_object.cpp
|
hle/kernel/k_auto_object.cpp
|
||||||
hle/kernel/k_auto_object.h
|
hle/kernel/k_auto_object.h
|
||||||
|
hle/kernel/k_auto_object_container.cpp
|
||||||
|
hle/kernel/k_auto_object_container.h
|
||||||
hle/kernel/k_affinity_mask.h
|
hle/kernel/k_affinity_mask.h
|
||||||
hle/kernel/k_condition_variable.cpp
|
hle/kernel/k_condition_variable.cpp
|
||||||
hle/kernel/k_condition_variable.h
|
hle/kernel/k_condition_variable.h
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
// Copyright 2021 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "core/hle/kernel/k_auto_object_container.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
void KAutoObjectWithListContainer::Register(KAutoObjectWithList* obj) {
|
||||||
|
KScopedLightLock lk(m_lock);
|
||||||
|
|
||||||
|
m_object_list.insert(*obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KAutoObjectWithListContainer::Unregister(KAutoObjectWithList* obj) {
|
||||||
|
KScopedLightLock lk(m_lock);
|
||||||
|
|
||||||
|
m_object_list.erase(m_object_list.iterator_to(*obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t KAutoObjectWithListContainer::GetOwnedCount(Process* owner) {
|
||||||
|
KScopedLightLock lk(m_lock);
|
||||||
|
|
||||||
|
size_t count = 0;
|
||||||
|
|
||||||
|
for (auto& obj : m_object_list) {
|
||||||
|
if (obj.GetOwner() == owner) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Kernel
|
|
@ -0,0 +1,72 @@
|
||||||
|
// Copyright 2021 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
#include "common/assert.h"
|
||||||
|
#include "common/common_funcs.h"
|
||||||
|
#include "common/common_types.h"
|
||||||
|
#include "common/intrusive_red_black_tree.h"
|
||||||
|
#include "core/hle/kernel/k_auto_object.h"
|
||||||
|
#include "core/hle/kernel/k_light_lock.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
class KernelCore;
|
||||||
|
class Process;
|
||||||
|
|
||||||
|
class KAutoObjectWithListContainer {
|
||||||
|
NON_COPYABLE(KAutoObjectWithListContainer);
|
||||||
|
NON_MOVEABLE(KAutoObjectWithListContainer);
|
||||||
|
|
||||||
|
public:
|
||||||
|
using ListType = Common::IntrusiveRedBlackTreeMemberTraits<
|
||||||
|
&KAutoObjectWithList::list_node>::TreeType<KAutoObjectWithList>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
class ListAccessor : public KScopedLightLock {
|
||||||
|
private:
|
||||||
|
ListType& m_list;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ListAccessor(KAutoObjectWithListContainer* container)
|
||||||
|
: KScopedLightLock(container->m_lock), m_list(container->m_object_list) { /* ... */
|
||||||
|
}
|
||||||
|
explicit ListAccessor(KAutoObjectWithListContainer& container)
|
||||||
|
: KScopedLightLock(container.m_lock), m_list(container.m_object_list) { /* ... */
|
||||||
|
}
|
||||||
|
|
||||||
|
typename ListType::iterator begin() const {
|
||||||
|
return m_list.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
typename ListType::iterator end() const {
|
||||||
|
return m_list.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
typename ListType::iterator find(typename ListType::const_reference ref) const {
|
||||||
|
return m_list.find(ref);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
friend class ListAccessor;
|
||||||
|
|
||||||
|
private:
|
||||||
|
KLightLock m_lock;
|
||||||
|
ListType m_object_list;
|
||||||
|
|
||||||
|
public:
|
||||||
|
KAutoObjectWithListContainer(KernelCore& kernel) : m_lock(kernel), m_object_list() {}
|
||||||
|
|
||||||
|
void Initialize() {}
|
||||||
|
void Finalize() {}
|
||||||
|
|
||||||
|
void Register(KAutoObjectWithList* obj);
|
||||||
|
void Unregister(KAutoObjectWithList* obj);
|
||||||
|
size_t GetOwnedCount(Process* owner);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Kernel
|
Loading…
Reference in New Issue