From 962cf97150fa95eaece7840e35abdb310905c51a Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 6 Apr 2021 23:33:33 -0700 Subject: [PATCH] kern: KLinkedList no longer exists --- .../mesosphere/kern_k_condition_variable.hpp | 2 +- .../include/mesosphere/kern_k_linked_list.hpp | 236 ------------------ .../kern_k_synchronization_object.hpp | 1 - .../source/init/kern_init_slab_setup.cpp | 3 +- .../source/kern_k_condition_variable.cpp | 32 +-- .../source/kern_k_dump_object.cpp | 1 - 6 files changed, 5 insertions(+), 270 deletions(-) delete mode 100644 libraries/libmesosphere/include/mesosphere/kern_k_linked_list.hpp diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_condition_variable.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_condition_variable.hpp index d967ea430..5a5eaaf81 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_condition_variable.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_condition_variable.hpp @@ -36,7 +36,7 @@ namespace ams::kern { void Signal(uintptr_t cv_key, s32 count); Result Wait(KProcessAddress addr, uintptr_t key, u32 value, s64 timeout); private: - KThread *SignalImpl(KThread *thread); + void SignalImpl(KThread *thread); }; ALWAYS_INLINE void BeforeUpdatePriority(KConditionVariable::ThreadTree *tree, KThread *thread) { diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_linked_list.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_linked_list.hpp deleted file mode 100644 index 2ed4cb900..000000000 --- a/libraries/libmesosphere/include/mesosphere/kern_k_linked_list.hpp +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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 . - */ -#pragma once -#include -#include -#include - -namespace ams::kern { - - class KLinkedListNode : public util::IntrusiveListBaseNode, public KSlabAllocated { - private: - void *m_item; - public: - constexpr KLinkedListNode() : util::IntrusiveListBaseNode(), m_item(nullptr) { MESOSPHERE_ASSERT_THIS(); } - - constexpr void Initialize(void *it) { - MESOSPHERE_ASSERT_THIS(); - m_item = it; - } - - constexpr void *GetItem() const { - return m_item; - } - }; - static_assert(sizeof(KLinkedListNode) == sizeof(util::IntrusiveListNode) + sizeof(void *)); - - template - class KLinkedList : private util::IntrusiveListBaseTraits::ListType { - private: - using BaseList = util::IntrusiveListBaseTraits::ListType; - public: - template - class Iterator; - - using value_type = T; - using size_type = size_t; - using difference_type = ptrdiff_t; - using pointer = value_type *; - using const_pointer = const value_type *; - using reference = value_type &; - using const_reference = const value_type &; - using iterator = Iterator; - using const_iterator = Iterator; - using reverse_iterator = std::reverse_iterator; - using const_reverse_iterator = std::reverse_iterator; - - template - class Iterator { - private: - using BaseIterator = BaseList::Iterator; - friend class KLinkedList; - public: - using iterator_category = std::bidirectional_iterator_tag; - using value_type = typename KLinkedList::value_type; - using difference_type = typename KLinkedList::difference_type; - using pointer = typename std::conditional::type; - using reference = typename std::conditional::type; - private: - BaseIterator m_base_it; - public: - explicit Iterator(BaseIterator it) : m_base_it(it) { /* ... */ } - - pointer GetItem() const { - return static_cast(m_base_it->GetItem()); - } - - bool operator==(const Iterator &rhs) const { - return m_base_it == rhs.m_base_it; - } - - bool operator!=(const Iterator &rhs) const { - return !(*this == rhs); - } - - pointer operator->() const { - return this->GetItem(); - } - - reference operator*() const { - return *this->GetItem(); - } - - Iterator &operator++() { - ++m_base_it; - return *this; - } - - Iterator &operator--() { - --m_base_it; - return *this; - } - - Iterator operator++(int) { - const Iterator it{*this}; - ++(*this); - return it; - } - - Iterator operator--(int) { - const Iterator it{*this}; - --(*this); - return it; - } - - operator Iterator() const { - return Iterator(m_base_it); - } - }; - public: - constexpr KLinkedList() : BaseList() { /* ... */ } - - ~KLinkedList() { - /* Erase all elements. */ - for (auto it = this->begin(); it != this->end(); it = this->erase(it)) { - /* ... */ - } - - /* Ensure we succeeded. */ - MESOSPHERE_ASSERT(this->empty()); - } - - /* Iterator accessors. */ - iterator begin() { - return iterator(BaseList::begin()); - } - - const_iterator begin() const { - return const_iterator(BaseList::begin()); - } - - iterator end() { - return iterator(BaseList::end()); - } - - const_iterator end() const { - return const_iterator(BaseList::end()); - } - - const_iterator cbegin() const { - return this->begin(); - } - - const_iterator cend() const { - return this->end(); - } - - reverse_iterator rbegin() { - return reverse_iterator(this->end()); - } - - const_reverse_iterator rbegin() const { - return const_reverse_iterator(this->end()); - } - - reverse_iterator rend() { - return reverse_iterator(this->begin()); - } - - const_reverse_iterator rend() const { - return const_reverse_iterator(this->begin()); - } - - const_reverse_iterator crbegin() const { - return this->rbegin(); - } - - const_reverse_iterator crend() const { - return this->rend(); - } - - /* Content management. */ - using BaseList::empty; - using BaseList::size; - - reference back() { - return *(--this->end()); - } - - const_reference back() const { - return *(--this->end()); - } - - reference front() { - return *this->begin(); - } - - const_reference front() const { - return *this->begin(); - } - - iterator insert(const_iterator pos, reference ref) { - KLinkedListNode *node = KLinkedListNode::Allocate(); - MESOSPHERE_ABORT_UNLESS(node != nullptr); - node->Initialize(std::addressof(ref)); - return iterator(BaseList::insert(pos.m_base_it, *node)); - } - - void push_back(reference ref) { - this->insert(this->end(), ref); - } - - void push_front(reference ref) { - this->insert(this->begin(), ref); - } - - void pop_back() { - this->erase(--this->end()); - } - - void pop_front() { - this->erase(this->begin()); - } - - iterator erase(const iterator pos) { - KLinkedListNode *freed_node = std::addressof(*pos.m_base_it); - iterator ret = iterator(BaseList::erase(pos.m_base_it)); - KLinkedListNode::Free(freed_node); - - return ret; - } - }; - -} diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_synchronization_object.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_synchronization_object.hpp index f1bf59197..ea340a155 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_synchronization_object.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_synchronization_object.hpp @@ -16,7 +16,6 @@ #pragma once #include #include -#include namespace ams::kern { diff --git a/libraries/libmesosphere/source/init/kern_init_slab_setup.cpp b/libraries/libmesosphere/source/init/kern_init_slab_setup.cpp index dcff4c205..5fab99370 100644 --- a/libraries/libmesosphere/source/init/kern_init_slab_setup.cpp +++ b/libraries/libmesosphere/source/init/kern_init_slab_setup.cpp @@ -22,7 +22,6 @@ namespace ams::kern::init { #define FOREACH_SLAB_TYPE(HANDLER, ...) \ HANDLER(KProcess, (SLAB_COUNT(KProcess)), ## __VA_ARGS__) \ HANDLER(KThread, (SLAB_COUNT(KThread)), ## __VA_ARGS__) \ - HANDLER(KLinkedListNode, (SLAB_COUNT(KThread)), ## __VA_ARGS__) \ HANDLER(KEvent, (SLAB_COUNT(KEvent)), ## __VA_ARGS__) \ HANDLER(KInterruptEvent, (SLAB_COUNT(KInterruptEvent)), ## __VA_ARGS__) \ HANDLER(KInterruptEventTask, (SLAB_COUNT(KInterruptEvent)), ## __VA_ARGS__) \ @@ -77,7 +76,7 @@ namespace ams::kern::init { namespace test { - constexpr size_t RequiredSizeForExtraThreadCount = SlabCountExtraKThread * (sizeof(KThread) + sizeof(KLinkedListNode) + (sizeof(KThreadLocalPage) / 8) + sizeof(KEventInfo)); + constexpr size_t RequiredSizeForExtraThreadCount = SlabCountExtraKThread * (sizeof(KThread) + (sizeof(KThreadLocalPage) / 8) + sizeof(KEventInfo)); static_assert(RequiredSizeForExtraThreadCount <= KernelSlabHeapAdditionalSize); } diff --git a/libraries/libmesosphere/source/kern_k_condition_variable.cpp b/libraries/libmesosphere/source/kern_k_condition_variable.cpp index 3234b87d9..ba25f35c4 100644 --- a/libraries/libmesosphere/source/kern_k_condition_variable.cpp +++ b/libraries/libmesosphere/source/kern_k_condition_variable.cpp @@ -118,7 +118,7 @@ namespace ams::kern { return cur_thread->GetWaitResult(std::addressof(dummy)); } - KThread *KConditionVariable::SignalImpl(KThread *thread) { + void KConditionVariable::SignalImpl(KThread *thread) { /* Check pre-conditions. */ MESOSPHERE_ASSERT(KScheduler::IsSchedulerLockedByCurrentThread()); @@ -137,7 +137,6 @@ namespace ams::kern { } } - KThread *thread_to_close = nullptr; if (AMS_LIKELY(can_access)) { if (prev_tag == ams::svc::InvalidHandle) { /* If nobody held the lock previously, we're all good. */ @@ -150,7 +149,7 @@ namespace ams::kern { if (AMS_LIKELY(owner_thread != nullptr)) { /* Add the thread as a waiter on the owner. */ owner_thread->AddWaiter(thread); - thread_to_close = owner_thread; + owner_thread->Close(); } else { /* The lock was tagged with a thread that doesn't exist. */ thread->SetSyncedObject(nullptr, svc::ResultInvalidState()); @@ -162,17 +161,9 @@ namespace ams::kern { thread->SetSyncedObject(nullptr, svc::ResultInvalidCurrentMemory()); thread->Wakeup(); } - - return thread_to_close; } void KConditionVariable::Signal(uintptr_t cv_key, s32 count) { - /* Prepare for signaling. */ - constexpr int MaxThreads = 16; - KLinkedList thread_list; - KThread *thread_array[MaxThreads]; - int num_to_close = 0; - /* Perform signaling. */ int num_waiters = 0; { @@ -182,14 +173,7 @@ namespace ams::kern { while ((it != m_tree.end()) && (count <= 0 || num_waiters < count) && (it->GetConditionVariableKey() == cv_key)) { KThread *target_thread = std::addressof(*it); - if (KThread *thread = this->SignalImpl(target_thread); thread != nullptr) { - if (num_to_close < MaxThreads) { - thread_array[num_to_close++] = thread; - } else { - thread_list.push_back(*thread); - } - } - + this->SignalImpl(target_thread); it = m_tree.erase(it); target_thread->ClearConditionVariable(); ++num_waiters; @@ -201,16 +185,6 @@ namespace ams::kern { WriteToUser(cv_key, std::addressof(has_waiter_flag)); } } - - /* Close threads in the array. */ - for (auto i = 0; i < num_to_close; ++i) { - thread_array[i]->Close(); - } - - /* Close threads in the list. */ - for (auto it = thread_list.begin(); it != thread_list.end(); it = thread_list.erase(it)) { - (*it).Close(); - } } Result KConditionVariable::Wait(KProcessAddress addr, uintptr_t key, u32 value, s64 timeout) { diff --git a/libraries/libmesosphere/source/kern_k_dump_object.cpp b/libraries/libmesosphere/source/kern_k_dump_object.cpp index 0a9a3f86a..1c8f3cb12 100644 --- a/libraries/libmesosphere/source/kern_k_dump_object.cpp +++ b/libraries/libmesosphere/source/kern_k_dump_object.cpp @@ -345,7 +345,6 @@ namespace ams::kern::KDumpObject { DUMP_KSLABOBJ(KDebug); DUMP_KSLABOBJ(KSession); DUMP_KSLABOBJ(KLightSession); - DUMP_KSLABOBJ(KLinkedListNode); DUMP_KSLABOBJ(KThreadLocalPage); DUMP_KSLABOBJ(KObjectName); DUMP_KSLABOBJ(KEventInfo);