diff options
author | bunnei <bunneidev@gmail.com> | 2021-04-01 06:06:02 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2021-05-06 01:40:49 +0200 |
commit | 34ce1dd7c724a4014ba4f8e7719f12352d0fddcb (patch) | |
tree | 574b3b57fb60233bd0cf6ef74eff49fe187f78ab /src/core/hle/kernel/k_auto_object_container.h | |
parent | hle: kernel: Add initial impl. of KAutoObject. (diff) | |
download | yuzu-34ce1dd7c724a4014ba4f8e7719f12352d0fddcb.tar yuzu-34ce1dd7c724a4014ba4f8e7719f12352d0fddcb.tar.gz yuzu-34ce1dd7c724a4014ba4f8e7719f12352d0fddcb.tar.bz2 yuzu-34ce1dd7c724a4014ba4f8e7719f12352d0fddcb.tar.lz yuzu-34ce1dd7c724a4014ba4f8e7719f12352d0fddcb.tar.xz yuzu-34ce1dd7c724a4014ba4f8e7719f12352d0fddcb.tar.zst yuzu-34ce1dd7c724a4014ba4f8e7719f12352d0fddcb.zip |
Diffstat (limited to 'src/core/hle/kernel/k_auto_object_container.h')
-rw-r--r-- | src/core/hle/kernel/k_auto_object_container.h | 72 |
1 files changed, 72 insertions, 0 deletions
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 @@ +// 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 |