2020-01-30 06:06:25 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
2020-01-30 23:29:51 +00:00
|
|
|
#include <mesosphere/kern_common.hpp>
|
2020-01-30 06:06:25 +00:00
|
|
|
#include <mesosphere/kern_k_auto_object.hpp>
|
|
|
|
#include <mesosphere/kern_k_light_lock.hpp>
|
|
|
|
|
|
|
|
namespace ams::kern {
|
|
|
|
|
|
|
|
class KAutoObjectWithListContainer {
|
|
|
|
NON_COPYABLE(KAutoObjectWithListContainer);
|
|
|
|
NON_MOVEABLE(KAutoObjectWithListContainer);
|
2020-07-31 08:59:46 +00:00
|
|
|
public:
|
2021-09-17 22:08:13 +00:00
|
|
|
using ListType = util::IntrusiveRedBlackTreeMemberTraits<&KAutoObjectWithList::m_list_node>::TreeType<KAutoObjectWithList>;
|
2020-01-30 06:06:25 +00:00
|
|
|
public:
|
|
|
|
class ListAccessor : public KScopedLightLock {
|
|
|
|
private:
|
2020-12-18 01:18:47 +00:00
|
|
|
ListType &m_list;
|
2020-01-30 06:06:25 +00:00
|
|
|
public:
|
2020-12-18 01:18:47 +00:00
|
|
|
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) { /* ... */ }
|
2020-01-30 06:06:25 +00:00
|
|
|
|
|
|
|
typename ListType::iterator begin() const {
|
2020-12-18 01:18:47 +00:00
|
|
|
return m_list.begin();
|
2020-01-30 06:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typename ListType::iterator end() const {
|
2020-12-18 01:18:47 +00:00
|
|
|
return m_list.end();
|
2020-01-30 06:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typename ListType::iterator find(typename ListType::const_reference ref) const {
|
2020-12-18 01:18:47 +00:00
|
|
|
return m_list.find(ref);
|
2020-01-30 06:06:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
friend class ListAccessor;
|
|
|
|
private:
|
2020-12-18 01:18:47 +00:00
|
|
|
KLightLock m_lock;
|
|
|
|
ListType m_object_list;
|
2020-01-30 06:06:25 +00:00
|
|
|
public:
|
2020-12-18 01:18:47 +00:00
|
|
|
constexpr KAutoObjectWithListContainer() : m_lock(), m_object_list() { MESOSPHERE_ASSERT_THIS(); }
|
2020-01-30 06:06:25 +00:00
|
|
|
|
2020-01-30 23:29:51 +00:00
|
|
|
void Initialize() { MESOSPHERE_ASSERT_THIS(); }
|
|
|
|
void Finalize() { MESOSPHERE_ASSERT_THIS(); }
|
2020-01-30 06:06:25 +00:00
|
|
|
|
2020-12-01 21:49:30 +00:00
|
|
|
void Register(KAutoObjectWithList *obj);
|
|
|
|
void Unregister(KAutoObjectWithList *obj);
|
2020-01-30 06:06:25 +00:00
|
|
|
size_t GetOwnedCount(KProcess *owner);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|