summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2021-03-31 21:06:02 -0700
committerGravatar bunnei2021-05-05 16:40:49 -0700
commit34ce1dd7c724a4014ba4f8e7719f12352d0fddcb (patch)
tree574b3b57fb60233bd0cf6ef74eff49fe187f78ab
parenthle: kernel: Add initial impl. of KAutoObject. (diff)
downloadyuzu-34ce1dd7c724a4014ba4f8e7719f12352d0fddcb.tar.gz
yuzu-34ce1dd7c724a4014ba4f8e7719f12352d0fddcb.tar.xz
yuzu-34ce1dd7c724a4014ba4f8e7719f12352d0fddcb.zip
hle: kernel: Add initial impl. of KAutoObjectWithListContainer.
Diffstat (limited to '')
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/core/hle/kernel/k_auto_object_container.cpp35
-rw-r--r--src/core/hle/kernel/k_auto_object_container.h72
3 files changed, 109 insertions, 0 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index aa83b8733..3cc5b7fbc 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -163,6 +163,8 @@ add_library(core STATIC
163 hle/kernel/k_address_space_info.h 163 hle/kernel/k_address_space_info.h
164 hle/kernel/k_auto_object.cpp 164 hle/kernel/k_auto_object.cpp
165 hle/kernel/k_auto_object.h 165 hle/kernel/k_auto_object.h
166 hle/kernel/k_auto_object_container.cpp
167 hle/kernel/k_auto_object_container.h
166 hle/kernel/k_affinity_mask.h 168 hle/kernel/k_affinity_mask.h
167 hle/kernel/k_condition_variable.cpp 169 hle/kernel/k_condition_variable.cpp
168 hle/kernel/k_condition_variable.h 170 hle/kernel/k_condition_variable.h
diff --git a/src/core/hle/kernel/k_auto_object_container.cpp b/src/core/hle/kernel/k_auto_object_container.cpp
new file mode 100644
index 000000000..9ba8a54c7
--- /dev/null
+++ b/src/core/hle/kernel/k_auto_object_container.cpp
@@ -0,0 +1,35 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "core/hle/kernel/k_auto_object_container.h"
6
7namespace Kernel {
8
9void KAutoObjectWithListContainer::Register(KAutoObjectWithList* obj) {
10 KScopedLightLock lk(m_lock);
11
12 m_object_list.insert(*obj);
13}
14
15void KAutoObjectWithListContainer::Unregister(KAutoObjectWithList* obj) {
16 KScopedLightLock lk(m_lock);
17
18 m_object_list.erase(m_object_list.iterator_to(*obj));
19}
20
21size_t KAutoObjectWithListContainer::GetOwnedCount(Process* owner) {
22 KScopedLightLock lk(m_lock);
23
24 size_t count = 0;
25
26 for (auto& obj : m_object_list) {
27 if (obj.GetOwner() == owner) {
28 count++;
29 }
30 }
31
32 return count;
33}
34
35} // namespace Kernel
diff --git a/src/core/hle/kernel/k_auto_object_container.h b/src/core/hle/kernel/k_auto_object_container.h
new file mode 100644
index 000000000..4b599b7c3
--- /dev/null
+++ b/src/core/hle/kernel/k_auto_object_container.h
@@ -0,0 +1,72 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <atomic>
8
9#include "common/assert.h"
10#include "common/common_funcs.h"
11#include "common/common_types.h"
12#include "common/intrusive_red_black_tree.h"
13#include "core/hle/kernel/k_auto_object.h"
14#include "core/hle/kernel/k_light_lock.h"
15
16namespace Kernel {
17
18class KernelCore;
19class Process;
20
21class KAutoObjectWithListContainer {
22 NON_COPYABLE(KAutoObjectWithListContainer);
23 NON_MOVEABLE(KAutoObjectWithListContainer);
24
25public:
26 using ListType = Common::IntrusiveRedBlackTreeMemberTraits<
27 &KAutoObjectWithList::list_node>::TreeType<KAutoObjectWithList>;
28
29public:
30 class ListAccessor : public KScopedLightLock {
31 private:
32 ListType& m_list;
33
34 public:
35 explicit ListAccessor(KAutoObjectWithListContainer* container)
36 : KScopedLightLock(container->m_lock), m_list(container->m_object_list) { /* ... */
37 }
38 explicit ListAccessor(KAutoObjectWithListContainer& container)
39 : KScopedLightLock(container.m_lock), m_list(container.m_object_list) { /* ... */
40 }
41
42 typename ListType::iterator begin() const {
43 return m_list.begin();
44 }
45
46 typename ListType::iterator end() const {
47 return m_list.end();
48 }
49
50 typename ListType::iterator find(typename ListType::const_reference ref) const {
51 return m_list.find(ref);
52 }
53 };
54
55 friend class ListAccessor;
56
57private:
58 KLightLock m_lock;
59 ListType m_object_list;
60
61public:
62 KAutoObjectWithListContainer(KernelCore& kernel) : m_lock(kernel), m_object_list() {}
63
64 void Initialize() {}
65 void Finalize() {}
66
67 void Register(KAutoObjectWithList* obj);
68 void Unregister(KAutoObjectWithList* obj);
69 size_t GetOwnedCount(Process* owner);
70};
71
72} // namespace Kernel