From 7444a68cd19003a851434984772b1729fa53c8e2 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 30 Sep 2021 19:00:47 -0700 Subject: [PATCH] os: adopt multiwait naming over waitable --- .../ddsf/ddsf_event_handler_manager.hpp | 6 +- .../ddsf/ddsf_i_event_handler.hpp | 20 +-- .../include/stratosphere/os.hpp | 2 +- .../include/stratosphere/os/os_event_api.hpp | 4 +- .../stratosphere/os/os_event_types.hpp | 4 +- .../os/os_interrupt_event_api.hpp | 4 +- .../os/os_interrupt_event_types.hpp | 4 +- .../stratosphere/os/os_message_queue_api.hpp | 4 +- .../os/os_message_queue_types.hpp | 6 +- .../{os_waitable.hpp => os_multiple_wait.hpp} | 6 +- .../stratosphere/os/os_multiple_wait_api.hpp | 45 ++++++ ...e_types.hpp => os_multiple_wait_types.hpp} | 16 +- .../os/os_multiple_wait_utils.hpp | 124 ++++++++++++++ .../os/os_sdk_reply_and_receive.hpp | 6 +- .../stratosphere/os/os_semaphore_api.hpp | 4 +- .../stratosphere/os/os_semaphore_types.hpp | 4 +- .../stratosphere/os/os_system_event_api.hpp | 4 +- .../stratosphere/os/os_system_event_types.hpp | 2 +- .../include/stratosphere/os/os_thread_api.hpp | 4 +- .../stratosphere/os/os_thread_types.hpp | 4 +- .../stratosphere/os/os_timer_event_api.hpp | 4 +- .../stratosphere/os/os_timer_event_types.hpp | 4 +- .../stratosphere/os/os_waitable_api.hpp | 45 ------ .../stratosphere/os/os_waitable_utils.hpp | 124 -------------- .../stratosphere/sf/hipc/sf_hipc_api.hpp | 4 +- .../sf/hipc/sf_hipc_server_manager.hpp | 63 ++++---- .../hipc/sf_hipc_server_session_manager.hpp | 8 +- ...able_object.hpp => tipc_object_holder.hpp} | 4 +- .../stratosphere/tipc/tipc_object_manager.hpp | 42 ++--- .../stratosphere/tipc/tipc_server_manager.hpp | 46 +++--- .../source/ddsf/ddsf_event_handler.cpp | 20 +-- .../source/erpt/srv/erpt_srv_service.cpp | 10 +- .../source/htclow/driver/htclow_usb_impl.cpp | 32 ++-- .../source/lm/srv/lm_ipc_server.cpp | 12 +- .../source/os/impl/os_inter_process_event.cpp | 6 +- .../source/os/impl/os_inter_process_event.hpp | 2 +- ...e.hpp => os_multiple_wait_holder_base.hpp} | 34 ++-- .../os/impl/os_multiple_wait_holder_impl.hpp | 59 +++++++ ...p => os_multiple_wait_holder_of_event.hpp} | 12 +- ... => os_multiple_wait_holder_of_handle.hpp} | 6 +- ...le_wait_holder_of_inter_process_event.hpp} | 6 +- ...ltiple_wait_holder_of_interrupt_event.cpp} | 4 +- ...ltiple_wait_holder_of_interrupt_event.hpp} | 6 +- ...multiple_wait_holder_of_message_queue.hpp} | 18 +-- ... os_multiple_wait_holder_of_semaphore.hpp} | 12 +- ... => os_multiple_wait_holder_of_thread.hpp} | 10 +- ...s_multiple_wait_holder_of_timer_event.hpp} | 14 +- ...ger_impl.cpp => os_multiple_wait_impl.cpp} | 37 ++--- ...ger_impl.hpp => os_multiple_wait_impl.hpp} | 66 ++++---- ...t.hpp => os_multiple_wait_object_list.hpp} | 20 +-- ..._multiple_wait_target_impl.os.horizon.cpp} | 26 +-- ..._multiple_wait_target_impl.os.horizon.hpp} | 4 +- .../source/os/impl/os_thread_manager.cpp | 8 +- .../source/os/impl/os_utility.hpp | 2 - .../os/impl/os_waitable_holder_impl.hpp | 59 ------- .../libstratosphere/source/os/os_event.cpp | 18 +-- .../source/os/os_interrupt_event.cpp | 10 +- .../source/os/os_message_queue.cpp | 12 +- .../source/os/os_multiple_wait.cpp | 152 ++++++++++++++++++ .../source/os/os_sdk_reply_and_receive.cpp | 24 +-- .../source/os/os_semaphore.cpp | 10 +- .../source/os/os_system_event.cpp | 8 +- .../libstratosphere/source/os/os_thread.cpp | 2 +- .../source/os/os_timer_event.cpp | 24 +-- .../libstratosphere/source/os/os_waitable.cpp | 152 ------------------ .../impl/osdbg_thread_type.os.horizon.hpp | 8 +- .../source/sf/hipc/sf_hipc_api.cpp | 8 +- .../source/sf/hipc/sf_hipc_server_manager.cpp | 62 +++---- .../hipc/sf_hipc_server_session_manager.cpp | 8 +- .../sdmmc/impl/sdmmc_device_detector.cpp | 48 +++--- .../sdmmc_sd_host_standard_controller.cpp | 22 +-- .../sdmmc_sd_host_standard_controller.hpp | 6 +- stratosphere/fatal/source/fatal_config.cpp | 10 +- stratosphere/fatal/source/fatal_config.hpp | 2 +- stratosphere/fatal/source/fatal_main.cpp | 6 +- .../pm/source/impl/pm_process_info.cpp | 8 +- .../pm/source/impl/pm_process_info.hpp | 6 +- .../pm/source/impl/pm_process_manager.cpp | 26 +-- stratosphere/sm/source/sm_tipc_server.cpp | 4 +- 79 files changed, 869 insertions(+), 869 deletions(-) rename libraries/libstratosphere/include/stratosphere/os/{os_waitable.hpp => os_multiple_wait.hpp} (80%) create mode 100644 libraries/libstratosphere/include/stratosphere/os/os_multiple_wait_api.hpp rename libraries/libstratosphere/include/stratosphere/os/{os_waitable_types.hpp => os_multiple_wait_types.hpp} (62%) create mode 100644 libraries/libstratosphere/include/stratosphere/os/os_multiple_wait_utils.hpp delete mode 100644 libraries/libstratosphere/include/stratosphere/os/os_waitable_api.hpp delete mode 100644 libraries/libstratosphere/include/stratosphere/os/os_waitable_utils.hpp rename libraries/libstratosphere/include/stratosphere/tipc/{tipc_waitable_object.hpp => tipc_object_holder.hpp} (94%) rename libraries/libstratosphere/source/os/impl/{os_waitable_holder_base.hpp => os_multiple_wait_holder_base.hpp} (70%) create mode 100644 libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_impl.hpp rename libraries/libstratosphere/source/os/impl/{os_waitable_holder_of_event.hpp => os_multiple_wait_holder_of_event.hpp} (77%) rename libraries/libstratosphere/source/os/impl/{os_waitable_holder_of_handle.hpp => os_multiple_wait_holder_of_handle.hpp} (83%) rename libraries/libstratosphere/source/os/impl/{os_waitable_holder_of_inter_process_event.hpp => os_multiple_wait_holder_of_inter_process_event.hpp} (82%) rename libraries/libstratosphere/source/os/impl/{os_waitable_holder_of_interrupt_event.cpp => os_multiple_wait_holder_of_interrupt_event.cpp} (86%) rename libraries/libstratosphere/source/os/impl/{os_waitable_holder_of_interrupt_event.hpp => os_multiple_wait_holder_of_interrupt_event.hpp} (81%) rename libraries/libstratosphere/source/os/impl/{os_waitable_holder_of_message_queue.hpp => os_multiple_wait_holder_of_message_queue.hpp} (78%) rename libraries/libstratosphere/source/os/impl/{os_waitable_holder_of_semaphore.hpp => os_multiple_wait_holder_of_semaphore.hpp} (78%) rename libraries/libstratosphere/source/os/impl/{os_waitable_holder_of_thread.hpp => os_multiple_wait_holder_of_thread.hpp} (80%) rename libraries/libstratosphere/source/os/impl/{os_waitable_holder_of_timer_event.hpp => os_multiple_wait_holder_of_timer_event.hpp} (80%) rename libraries/libstratosphere/source/os/impl/{os_waitable_manager_impl.cpp => os_multiple_wait_impl.cpp} (81%) rename libraries/libstratosphere/source/os/impl/{os_waitable_manager_impl.hpp => os_multiple_wait_impl.hpp} (50%) rename libraries/libstratosphere/source/os/impl/{os_waitable_object_list.hpp => os_multiple_wait_object_list.hpp} (63%) rename libraries/libstratosphere/source/os/impl/{os_waitable_manager_target_impl.os.horizon.cpp => os_multiple_wait_target_impl.os.horizon.cpp} (66%) rename libraries/libstratosphere/source/os/impl/{os_waitable_manager_target_impl.os.horizon.hpp => os_multiple_wait_target_impl.os.horizon.hpp} (96%) delete mode 100644 libraries/libstratosphere/source/os/impl/os_waitable_holder_impl.hpp create mode 100644 libraries/libstratosphere/source/os/os_multiple_wait.cpp delete mode 100644 libraries/libstratosphere/source/os/os_waitable.cpp diff --git a/libraries/libstratosphere/include/stratosphere/ddsf/ddsf_event_handler_manager.hpp b/libraries/libstratosphere/include/stratosphere/ddsf/ddsf_event_handler_manager.hpp index 1b3070b24..0c86fd9be 100644 --- a/libraries/libstratosphere/include/stratosphere/ddsf/ddsf_event_handler_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/ddsf/ddsf_event_handler_manager.hpp @@ -31,10 +31,10 @@ namespace ams::ddsf { bool is_initialized; bool is_looping; os::SdkConditionVariable is_looping_cv; - os::WaitableManagerType waitable_manager; + os::MultiWaitType multi_wait; os::ThreadType *loop_thread; os::Event loop_control_event; - os::WaitableHolderType loop_control_event_holder; + os::MultiWaitHolderType loop_control_event_holder; LoopControlCommandParameters *loop_control_command_params; os::LightEvent loop_control_command_done_event; os::SdkMutex loop_control_lock; @@ -43,7 +43,7 @@ namespace ams::ddsf { void ProcessControlCommandImpl(LoopControlCommandParameters *params); public: EventHandlerManager() - : is_initialized(false), is_looping(false), is_looping_cv(), waitable_manager(), + : is_initialized(false), is_looping(false), is_looping_cv(), multi_wait(), loop_thread(), loop_control_event(os::EventClearMode_AutoClear), loop_control_event_holder(), loop_control_command_params(), loop_control_command_done_event(os::EventClearMode_AutoClear), loop_control_lock() diff --git a/libraries/libstratosphere/include/stratosphere/ddsf/ddsf_i_event_handler.hpp b/libraries/libstratosphere/include/stratosphere/ddsf/ddsf_i_event_handler.hpp index 4d85f1425..efe34b3be 100644 --- a/libraries/libstratosphere/include/stratosphere/ddsf/ddsf_i_event_handler.hpp +++ b/libraries/libstratosphere/include/stratosphere/ddsf/ddsf_i_event_handler.hpp @@ -26,27 +26,27 @@ namespace ams::ddsf { NON_MOVEABLE(IEventHandler); friend class EventHandlerManager; private: - os::WaitableHolderType holder; + os::MultiWaitHolderType holder; uintptr_t user_data; bool is_initialized; bool is_registered; private: - void Link(os::WaitableManagerType *manager) { + void Link(os::MultiWaitType *multi_wait) { AMS_ASSERT(this->IsInitialized()); AMS_ASSERT(!this->IsRegistered()); - AMS_ASSERT(manager != nullptr); - os::LinkWaitableHolder(manager, std::addressof(this->holder)); + AMS_ASSERT(multi_wait != nullptr); + os::LinkMultiWaitHolder(multi_wait, std::addressof(this->holder)); } void Unlink() { AMS_ASSERT(this->IsInitialized()); AMS_ASSERT(this->IsRegistered()); - os::UnlinkWaitableHolder(std::addressof(this->holder)); + os::UnlinkMultiWaitHolder(std::addressof(this->holder)); } - static IEventHandler &ToEventHandler(os::WaitableHolderType *holder) { + static IEventHandler &ToEventHandler(os::MultiWaitHolderType *holder) { AMS_ASSERT(holder != nullptr); - auto &event_handler = *reinterpret_cast(os::GetWaitableHolderUserData(holder)); + auto &event_handler = *reinterpret_cast(os::GetMultiWaitHolderUserData(holder)); AMS_ASSERT(event_handler.IsInitialized()); return event_handler; } @@ -72,8 +72,8 @@ namespace ams::ddsf { void Initialize(T *object) { AMS_ASSERT(object != nullptr); AMS_ASSERT(!this->IsInitialized()); - os::InitializeWaitableHolder(std::addressof(this->holder), object); - os::SetWaitableHolderUserData(std::addressof(this->holder), reinterpret_cast(this)); + os::InitializeMultiWaitHolder(std::addressof(this->holder), object); + os::SetMultiWaitHolderUserData(std::addressof(this->holder), reinterpret_cast(this)); this->is_initialized = true; this->is_registered = false; } @@ -81,7 +81,7 @@ namespace ams::ddsf { void Finalize() { AMS_ASSERT(this->IsInitialized()); AMS_ASSERT(!this->IsRegistered()); - os::FinalizeWaitableHolder(std::addressof(this->holder)); + os::FinalizeMultiWaitHolder(std::addressof(this->holder)); this->is_initialized = false; this->is_registered = false; } diff --git a/libraries/libstratosphere/include/stratosphere/os.hpp b/libraries/libstratosphere/include/stratosphere/os.hpp index 5ce3c2597..6e94c659e 100644 --- a/libraries/libstratosphere/include/stratosphere/os.hpp +++ b/libraries/libstratosphere/include/stratosphere/os.hpp @@ -50,4 +50,4 @@ #include #include #include -#include +#include diff --git a/libraries/libstratosphere/include/stratosphere/os/os_event_api.hpp b/libraries/libstratosphere/include/stratosphere/os/os_event_api.hpp index 0f7b75016..804a3ac60 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_event_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_event_api.hpp @@ -21,7 +21,7 @@ namespace ams::os { struct EventType; - struct WaitableHolderType; + struct MultiWaitHolderType; void InitializeEvent(EventType *event, bool signaled, EventClearMode clear_mode); void FinalizeEvent(EventType *event); @@ -32,6 +32,6 @@ namespace ams::os { bool TimedWaitEvent(EventType *event, TimeSpan timeout); void ClearEvent(EventType *event); - void InitializeWaitableHolder(WaitableHolderType *waitable_holder, EventType *event); + void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, EventType *event); } diff --git a/libraries/libstratosphere/include/stratosphere/os/os_event_types.hpp b/libraries/libstratosphere/include/stratosphere/os/os_event_types.hpp index 7b61a5cea..9f73ecc0f 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_event_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_event_types.hpp @@ -23,7 +23,7 @@ namespace ams::os { namespace impl { - class WaitableObjectList; + class MultiWaitObjectList; } @@ -33,7 +33,7 @@ namespace ams::os { State_Initialized = 1, }; - util::TypedStorage waitable_object_list_storage; + util::TypedStorage multi_wait_object_list_storage; bool signaled; bool initially_signaled; u8 clear_mode; diff --git a/libraries/libstratosphere/include/stratosphere/os/os_interrupt_event_api.hpp b/libraries/libstratosphere/include/stratosphere/os/os_interrupt_event_api.hpp index b2dcf794a..68e265c00 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_interrupt_event_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_interrupt_event_api.hpp @@ -21,7 +21,7 @@ namespace ams::os { struct InterruptEventType; - struct WaitableHolderType; + struct MultiWaitHolderType; void InitializeInterruptEvent(InterruptEventType *event, InterruptName name, EventClearMode clear_mode); void FinalizeInterruptEvent(InterruptEventType *event); @@ -31,6 +31,6 @@ namespace ams::os { bool TimedWaitInterruptEvent(InterruptEventType *event, TimeSpan timeout); void ClearInterruptEvent(InterruptEventType *event); - void InitializeWaitableHolder(WaitableHolderType *waitable_holder, InterruptEventType *event); + void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, InterruptEventType *event); } diff --git a/libraries/libstratosphere/include/stratosphere/os/os_interrupt_event_types.hpp b/libraries/libstratosphere/include/stratosphere/os/os_interrupt_event_types.hpp index 685832096..d9d2d17d1 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_interrupt_event_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_interrupt_event_types.hpp @@ -23,7 +23,7 @@ namespace ams::os { namespace impl { - class WaitableObjectList; + class MultiWaitObjectList; class InterruptEventImpl; } @@ -34,7 +34,7 @@ namespace ams::os { State_Initialized = 1, }; - util::TypedStorage waitable_object_list_storage; + util::TypedStorage multi_wait_object_list_storage; u8 clear_mode; u8 state; diff --git a/libraries/libstratosphere/include/stratosphere/os/os_message_queue_api.hpp b/libraries/libstratosphere/include/stratosphere/os/os_message_queue_api.hpp index 0f772a459..576ea2361 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_message_queue_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_message_queue_api.hpp @@ -21,7 +21,7 @@ namespace ams::os { struct MessageQueueType; - struct WaitableHolderType; + struct MultiWaitHolderType; void InitializeMessageQueue(MessageQueueType *mq, uintptr_t *buffer, size_t count); void FinalizeMessageQueue(MessageQueueType *mq); @@ -46,6 +46,6 @@ namespace ams::os { bool TryPeekMessageQueue(uintptr_t *out, const MessageQueueType *mq); bool TimedPeekMessageQueue(uintptr_t *out, const MessageQueueType *mq, TimeSpan timeout); - void InitializeWaitableHolder(WaitableHolderType *waitable_holder, MessageQueueType *event, MessageQueueWaitType wait_type); + void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, MessageQueueType *event, MessageQueueWaitType wait_type); } diff --git a/libraries/libstratosphere/include/stratosphere/os/os_message_queue_types.hpp b/libraries/libstratosphere/include/stratosphere/os/os_message_queue_types.hpp index 7c7789c64..1542aa54d 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_message_queue_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_message_queue_types.hpp @@ -23,7 +23,7 @@ namespace ams::os { namespace impl { - class WaitableObjectList; + class MultiWaitObjectList; } @@ -33,8 +33,8 @@ namespace ams::os { State_Initialized = 1, }; - util::TypedStorage waitlist_not_full; - util::TypedStorage waitlist_not_empty; + util::TypedStorage waitlist_not_full; + util::TypedStorage waitlist_not_empty; uintptr_t *buffer; s32 capacity; s32 count; diff --git a/libraries/libstratosphere/include/stratosphere/os/os_waitable.hpp b/libraries/libstratosphere/include/stratosphere/os/os_multiple_wait.hpp similarity index 80% rename from libraries/libstratosphere/include/stratosphere/os/os_waitable.hpp rename to libraries/libstratosphere/include/stratosphere/os/os_multiple_wait.hpp index 13fa5c9f7..bbb1c190c 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_waitable.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_multiple_wait.hpp @@ -14,6 +14,6 @@ * along with this program. If not, see . */ #pragma once -#include -#include -#include +#include +#include +#include diff --git a/libraries/libstratosphere/include/stratosphere/os/os_multiple_wait_api.hpp b/libraries/libstratosphere/include/stratosphere/os/os_multiple_wait_api.hpp new file mode 100644 index 000000000..7f9c4218e --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/os/os_multiple_wait_api.hpp @@ -0,0 +1,45 @@ +/* + * 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 + +namespace ams::os { + + struct MultiWaitHolderType; + struct MultiWaitType; + + void InitializeMultiWait(MultiWaitType *multi_wait); + void FinalizeMultiWait(MultiWaitType *multi_wait); + + MultiWaitHolderType *WaitAny(MultiWaitType *multi_wait); + MultiWaitHolderType *TryWaitAny(MultiWaitType *multi_wait); + MultiWaitHolderType *TimedWaitAny(MultiWaitType *multi_wait, TimeSpan timeout); + + void FinalizeMultiWaitHolder(MultiWaitHolderType *holder); + + void LinkMultiWaitHolder(MultiWaitType *multi_wait, MultiWaitHolderType *holder); + void UnlinkMultiWaitHolder(MultiWaitHolderType *holder); + void UnlinkAllMultiWaitHolder(MultiWaitType *multi_wait); + + void MoveAllMultiWaitHolder(MultiWaitType *dst, MultiWaitType *src); + + void SetMultiWaitHolderUserData(MultiWaitHolderType *holder, uintptr_t user_data); + uintptr_t GetMultiWaitHolderUserData(const MultiWaitHolderType *holder); + + void InitializeMultiWaitHolder(MultiWaitHolderType *holder, Handle handle); + +} diff --git a/libraries/libstratosphere/include/stratosphere/os/os_waitable_types.hpp b/libraries/libstratosphere/include/stratosphere/os/os_multiple_wait_types.hpp similarity index 62% rename from libraries/libstratosphere/include/stratosphere/os/os_waitable_types.hpp rename to libraries/libstratosphere/include/stratosphere/os/os_multiple_wait_types.hpp index d4aa47fd3..48ccbc28d 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_waitable_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_multiple_wait_types.hpp @@ -21,12 +21,12 @@ namespace ams::os { namespace impl { - class WaitableManagerImpl; - struct WaitableHolderImpl; + class MultiWaitImpl; + struct MultiWaitHolderImpl; } - struct WaitableManagerType { + struct MultiWaitType { enum State { State_NotInitialized, State_Initialized, @@ -34,14 +34,14 @@ namespace ams::os { u8 state; bool is_waiting; - util::TypedStorage impl_storage; + util::TypedStorage impl_storage; }; - static_assert(std::is_trivial::value); + static_assert(std::is_trivial::value); - struct WaitableHolderType { - util::TypedStorage impl_storage; + struct MultiWaitHolderType { + util::TypedStorage impl_storage; uintptr_t user_data; }; - static_assert(std::is_trivial::value); + static_assert(std::is_trivial::value); } diff --git a/libraries/libstratosphere/include/stratosphere/os/os_multiple_wait_utils.hpp b/libraries/libstratosphere/include/stratosphere/os/os_multiple_wait_utils.hpp new file mode 100644 index 000000000..a0612d156 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/os/os_multiple_wait_utils.hpp @@ -0,0 +1,124 @@ +/* + * 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 +#include + +namespace ams::os { + + namespace impl { + + class AutoMultiWaitHolder { + private: + MultiWaitHolderType m_holder; + public: + template + ALWAYS_INLINE explicit AutoMultiWaitHolder(MultiWaitType *multi_wait, T &&arg) { + InitializeMultiWaitHolder(std::addressof(m_holder), std::forward(arg)); + LinkMultiWaitHolder(multi_wait, std::addressof(m_holder)); + } + + ALWAYS_INLINE ~AutoMultiWaitHolder() { + UnlinkMultiWaitHolder(std::addressof(m_holder)); + FinalizeMultiWaitHolder(std::addressof(m_holder)); + } + + ALWAYS_INLINE std::pair ConvertResult(const std::pair result, int index) { + if (result.first == std::addressof(m_holder)) { + return std::make_pair(static_cast(nullptr), index); + } else { + return result; + } + } + }; + + template + inline std::pair WaitAnyImpl(F &&func, MultiWaitType *multi_wait, int) { + return std::pair(func(multi_wait), -1); + } + + template + inline std::pair WaitAnyImpl(F &&func, MultiWaitType *multi_wait, int index, T &&x, Args &&... args) { + AutoMultiWaitHolder holder(multi_wait, std::forward(x)); + return holder.ConvertResult(WaitAnyImpl(std::forward(func), multi_wait, index + 1, std::forward(args)...), index); + } + + template + inline std::pair WaitAnyImpl(F &&func, MultiWaitType *multi_wait, Args &&... args) { + return WaitAnyImpl(std::forward(func), multi_wait, 0, std::forward(args)...); + } + + class TempMultiWait { + private: + MultiWaitType m_multi_wait; + public: + ALWAYS_INLINE TempMultiWait() { + os::InitializeMultiWait(std::addressof(m_multi_wait)); + } + + ALWAYS_INLINE ~TempMultiWait() { + os::FinalizeMultiWait(std::addressof(m_multi_wait)); + } + + MultiWaitType *Get() { + return std::addressof(m_multi_wait); + } + }; + + template + inline std::pair WaitAnyImpl(F &&func, Args &&... args) { + TempMultiWait temp_multi_wait; + return WaitAnyImpl(std::forward(func), temp_multi_wait.Get(), 0, std::forward(args)...); + } + + using WaitAnyFunction = MultiWaitHolderType * (*)(MultiWaitType *); + + class NotBoolButInt { + private: + int m_value; + public: + constexpr ALWAYS_INLINE NotBoolButInt(int v) : m_value(v) { /* ... */ } + + constexpr ALWAYS_INLINE operator int() const { return m_value; } + + explicit operator bool() const = delete; + }; + + } + + template requires (sizeof...(Args) > 0) + inline std::pair WaitAny(MultiWaitType *multi_wait, Args &&... args) { + return impl::WaitAnyImpl(static_cast(&::ams::os::WaitAny), multi_wait, std::forward(args)...); + } + + template requires (sizeof...(Args) > 0) + inline int WaitAny(Args &&... args) { + return impl::WaitAnyImpl(static_cast(&::ams::os::WaitAny), std::forward(args)...).second; + } + + template requires (sizeof...(Args) > 0) + inline std::pair TryWaitAny(MultiWaitType *multi_wait, Args &&... args) { + return impl::WaitAnyImpl(static_cast(&::ams::os::TryWaitAny), multi_wait, std::forward(args)...); + } + + template requires (sizeof...(Args) > 0) + inline impl::NotBoolButInt TryWaitAny(Args &&... args) { + return impl::WaitAnyImpl(static_cast(&::ams::os::TryWaitAny), std::forward(args)...).second; + } + +} diff --git a/libraries/libstratosphere/include/stratosphere/os/os_sdk_reply_and_receive.hpp b/libraries/libstratosphere/include/stratosphere/os/os_sdk_reply_and_receive.hpp index a88967c48..3ed8c496c 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_sdk_reply_and_receive.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_sdk_reply_and_receive.hpp @@ -18,9 +18,9 @@ namespace ams::os { - struct WaitableHolderType; - struct WaitableManagerType; + struct MultiWaitHolderType; + struct MultiWaitType; - Result SdkReplyAndReceive(os::WaitableHolderType **out, Handle reply_target, WaitableManagerType *manager); + Result SdkReplyAndReceive(os::MultiWaitHolderType **out, Handle reply_target, MultiWaitType *multi_wait); } diff --git a/libraries/libstratosphere/include/stratosphere/os/os_semaphore_api.hpp b/libraries/libstratosphere/include/stratosphere/os/os_semaphore_api.hpp index bd761911a..79ac7c4d8 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_semaphore_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_semaphore_api.hpp @@ -20,7 +20,7 @@ namespace ams::os { struct SemaphoreType; - struct WaitableHolderType; + struct MultiWaitHolderType; void InitializeSemaphore(SemaphoreType *sema, s32 count, s32 max_count); void FinalizeSemaphore(SemaphoreType *sema); @@ -34,6 +34,6 @@ namespace ams::os { s32 GetCurrentSemaphoreCount(const SemaphoreType *sema); - void InitializeWaitableHolder(WaitableHolderType *waitable_holder, SemaphoreType *sema); + void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, SemaphoreType *sema); } diff --git a/libraries/libstratosphere/include/stratosphere/os/os_semaphore_types.hpp b/libraries/libstratosphere/include/stratosphere/os/os_semaphore_types.hpp index 128736679..8168ece47 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_semaphore_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_semaphore_types.hpp @@ -23,7 +23,7 @@ namespace ams::os { namespace impl { - class WaitableObjectList; + class MultiWaitObjectList; } @@ -33,7 +33,7 @@ namespace ams::os { State_Initialized = 1, }; - util::TypedStorage waitlist; + util::TypedStorage waitlist; u8 state; s32 count; s32 max_count; diff --git a/libraries/libstratosphere/include/stratosphere/os/os_system_event_api.hpp b/libraries/libstratosphere/include/stratosphere/os/os_system_event_api.hpp index d31c0e044..837c3ffdd 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_system_event_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_system_event_api.hpp @@ -21,7 +21,7 @@ namespace ams::os { struct SystemEventType; - struct WaitableHolderType; + struct MultiWaitHolderType; Result CreateSystemEvent(SystemEventType *event, EventClearMode clear_mode, bool inter_process); void DestroySystemEvent(SystemEventType *event); @@ -42,6 +42,6 @@ namespace ams::os { bool TimedWaitSystemEvent(SystemEventType *event, TimeSpan timeout); void ClearSystemEvent(SystemEventType *event); - void InitializeWaitableHolder(WaitableHolderType *waitable_holder, SystemEventType *event); + void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, SystemEventType *event); } diff --git a/libraries/libstratosphere/include/stratosphere/os/os_system_event_types.hpp b/libraries/libstratosphere/include/stratosphere/os/os_system_event_types.hpp index cff31bc0e..323942196 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_system_event_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_system_event_types.hpp @@ -28,7 +28,7 @@ namespace ams::os { State_Initialized = 1, }; - util::TypedStorage waitable_object_list_storage; + util::TypedStorage multi_wait_object_list_storage; bool auto_clear; u8 state; diff --git a/libraries/libstratosphere/include/stratosphere/os/os_thread_api.hpp b/libraries/libstratosphere/include/stratosphere/os/os_thread_api.hpp index 3d7c42166..b2ec9a431 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_thread_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_thread_api.hpp @@ -21,7 +21,7 @@ namespace ams::os { struct ThreadType; - struct WaitableHolderType; + struct MultiWaitHolderType; Result CreateThread(ThreadType *thread, ThreadFunction function, void *argument, void *stack, size_t stack_size, s32 priority, s32 ideal_core); Result CreateThread(ThreadType *thread, ThreadFunction function, void *argument, void *stack, size_t stack_size, s32 priority); @@ -62,6 +62,6 @@ namespace ams::os { ThreadId GetThreadId(const ThreadType *thread); - void InitializeWaitableHolder(WaitableHolderType *holder, ThreadType *thread); + void InitializeMultiWaitHolder(MultiWaitHolderType *holder, ThreadType *thread); } diff --git a/libraries/libstratosphere/include/stratosphere/os/os_thread_types.hpp b/libraries/libstratosphere/include/stratosphere/os/os_thread_types.hpp index a0662fd66..9a9a3ef67 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_thread_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_thread_types.hpp @@ -26,7 +26,7 @@ namespace ams::os { namespace impl { - class WaitableObjectList; + class MultiWaitObjectList; } @@ -47,7 +47,7 @@ namespace ams::os { }; util::TypedStorage all_threads_node; - util::TypedStorage waitlist; + util::TypedStorage waitlist; uintptr_t reserved[4]; u8 state; u8 suspend_count; diff --git a/libraries/libstratosphere/include/stratosphere/os/os_timer_event_api.hpp b/libraries/libstratosphere/include/stratosphere/os/os_timer_event_api.hpp index 40d58ef51..c9e61068d 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_timer_event_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_timer_event_api.hpp @@ -21,7 +21,7 @@ namespace ams::os { struct TimerEventType; - struct WaitableHolderType; + struct MultiWaitHolderType; void InitializeTimerEvent(TimerEventType *event, EventClearMode clear_mode); void FinalizeTimerEvent(TimerEventType *event); @@ -36,6 +36,6 @@ namespace ams::os { void SignalTimerEvent(TimerEventType *event); void ClearTimerEvent(TimerEventType *event); - void InitializeWaitableHolder(WaitableHolderType *waitable_holder, TimerEventType *event); + void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, TimerEventType *event); } diff --git a/libraries/libstratosphere/include/stratosphere/os/os_timer_event_types.hpp b/libraries/libstratosphere/include/stratosphere/os/os_timer_event_types.hpp index 975445d78..652c0adb6 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_timer_event_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/os/os_timer_event_types.hpp @@ -24,7 +24,7 @@ namespace ams::os { namespace impl { - class WaitableObjectList; + class MultiWaitObjectList; } @@ -42,7 +42,7 @@ namespace ams::os { TimerState_Periodic = 2, }; - util::TypedStorage waitable_object_list_storage; + util::TypedStorage multi_wait_object_list_storage; u8 state; u8 clear_mode; diff --git a/libraries/libstratosphere/include/stratosphere/os/os_waitable_api.hpp b/libraries/libstratosphere/include/stratosphere/os/os_waitable_api.hpp deleted file mode 100644 index 2ede0d930..000000000 --- a/libraries/libstratosphere/include/stratosphere/os/os_waitable_api.hpp +++ /dev/null @@ -1,45 +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 - -namespace ams::os { - - struct WaitableHolderType; - struct WaitableManagerType; - - void InitializeWaitableManager(WaitableManagerType *manager); - void FinalizeWaitableManager(WaitableManagerType *manager); - - WaitableHolderType *WaitAny(WaitableManagerType *manager); - WaitableHolderType *TryWaitAny(WaitableManagerType *manager); - WaitableHolderType *TimedWaitAny(WaitableManagerType *manager, TimeSpan timeout); - - void FinalizeWaitableHolder(WaitableHolderType *holder); - - void LinkWaitableHolder(WaitableManagerType *manager, WaitableHolderType *holder); - void UnlinkWaitableHolder(WaitableHolderType *holder); - void UnlinkAllWaitableHolder(WaitableManagerType *manager); - - void MoveAllWaitableHolder(WaitableManagerType *dst, WaitableManagerType *src); - - void SetWaitableHolderUserData(WaitableHolderType *holder, uintptr_t user_data); - uintptr_t GetWaitableHolderUserData(const WaitableHolderType *holder); - - void InitializeWaitableHolder(WaitableHolderType *holder, Handle handle); - -} diff --git a/libraries/libstratosphere/include/stratosphere/os/os_waitable_utils.hpp b/libraries/libstratosphere/include/stratosphere/os/os_waitable_utils.hpp deleted file mode 100644 index 6cfd5ab7a..000000000 --- a/libraries/libstratosphere/include/stratosphere/os/os_waitable_utils.hpp +++ /dev/null @@ -1,124 +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 -#include - -namespace ams::os { - - namespace impl { - - class AutoWaitableHolder { - private: - WaitableHolderType m_holder; - public: - template - ALWAYS_INLINE explicit AutoWaitableHolder(WaitableManagerType *manager, T &&arg) { - InitializeWaitableHolder(std::addressof(m_holder), std::forward(arg)); - LinkWaitableHolder(manager, std::addressof(m_holder)); - } - - ALWAYS_INLINE ~AutoWaitableHolder() { - UnlinkWaitableHolder(std::addressof(m_holder)); - FinalizeWaitableHolder(std::addressof(m_holder)); - } - - ALWAYS_INLINE std::pair ConvertResult(const std::pair result, int index) { - if (result.first == std::addressof(m_holder)) { - return std::make_pair(static_cast(nullptr), index); - } else { - return result; - } - } - }; - - template - inline std::pair WaitAnyImpl(F &&func, WaitableManagerType *manager, int) { - return std::pair(func(manager), -1); - } - - template - inline std::pair WaitAnyImpl(F &&func, WaitableManagerType *manager, int index, T &&x, Args &&... args) { - AutoWaitableHolder holder(manager, std::forward(x)); - return holder.ConvertResult(WaitAnyImpl(std::forward(func), manager, index + 1, std::forward(args)...), index); - } - - template - inline std::pair WaitAnyImpl(F &&func, WaitableManagerType *manager, Args &&... args) { - return WaitAnyImpl(std::forward(func), manager, 0, std::forward(args)...); - } - - class TempWaitableManager { - private: - WaitableManagerType m_manager; - public: - ALWAYS_INLINE TempWaitableManager() { - os::InitializeWaitableManager(std::addressof(m_manager)); - } - - ALWAYS_INLINE ~TempWaitableManager() { - os::FinalizeWaitableManager(std::addressof(m_manager)); - } - - WaitableManagerType *Get() { - return std::addressof(m_manager); - } - }; - - template - inline std::pair WaitAnyImpl(F &&func, Args &&... args) { - TempWaitableManager temp_manager; - return WaitAnyImpl(std::forward(func), temp_manager.Get(), 0, std::forward(args)...); - } - - using WaitAnyFunction = WaitableHolderType * (*)(WaitableManagerType *); - - class NotBoolButInt { - private: - int m_value; - public: - constexpr ALWAYS_INLINE NotBoolButInt(int v) : m_value(v) { /* ... */ } - - constexpr ALWAYS_INLINE operator int() const { return m_value; } - - explicit operator bool() const = delete; - }; - - } - - template requires (sizeof...(Args) > 0) - inline std::pair WaitAny(WaitableManagerType *manager, Args &&... args) { - return impl::WaitAnyImpl(static_cast(&::ams::os::WaitAny), manager, std::forward(args)...); - } - - template requires (sizeof...(Args) > 0) - inline int WaitAny(Args &&... args) { - return impl::WaitAnyImpl(static_cast(&::ams::os::WaitAny), std::forward(args)...).second; - } - - template requires (sizeof...(Args) > 0) - inline std::pair TryWaitAny(WaitableManagerType *manager, Args &&... args) { - return impl::WaitAnyImpl(static_cast(&::ams::os::TryWaitAny), manager, std::forward(args)...); - } - - template requires (sizeof...(Args) > 0) - inline impl::NotBoolButInt TryWaitAny(Args &&... args) { - return impl::WaitAnyImpl(static_cast(&::ams::os::TryWaitAny), std::forward(args)...).second; - } - -} diff --git a/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_api.hpp b/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_api.hpp index 0b7c501e7..dfb20ccc6 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_api.hpp @@ -28,8 +28,8 @@ namespace ams::sf::hipc { NeedsRetry, }; - void AttachWaitableHolderForAccept(os::WaitableHolderType *holder, Handle port); - void AttachWaitableHolderForReply(os::WaitableHolderType *holder, Handle request); + void AttachMultiWaitHolderForAccept(os::MultiWaitHolderType *holder, Handle port); + void AttachMultiWaitHolderForReply(os::MultiWaitHolderType *holder, Handle request); Result Receive(ReceiveResult *out_recv_result, Handle session_handle, const cmif::PointerAndSize &message_buffer); Result Receive(bool *out_closed, Handle session_handle, const cmif::PointerAndSize &message_buffer); diff --git a/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp b/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp index 0f1b2e4aa..a50792e36 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp @@ -47,7 +47,7 @@ namespace ams::sf::hipc { using ServerDomainSessionManager::DomainEntryStorage; using ServerDomainSessionManager::DomainStorage; protected: - class Server : public os::WaitableHolderType { + class Server : public os::MultiWaitHolderType { friend class ServerManagerBase; template friend class ServerManager; @@ -73,42 +73,42 @@ namespace ams::sf::hipc { } }; private: - /* Management of waitables. */ - os::WaitableManagerType waitable_manager; + /* Multiple wait management. */ + os::MultiWaitType multi_wait; os::Event request_stop_event; - os::WaitableHolderType request_stop_event_holder; + os::MultiWaitHolderType request_stop_event_holder; os::Event notify_event; - os::WaitableHolderType notify_event_holder; + os::MultiWaitHolderType notify_event_holder; - os::SdkMutex waitable_selection_mutex; + os::SdkMutex selection_mutex; - os::SdkMutex waitlist_mutex; - os::WaitableManagerType waitlist; + os::SdkMutex deferred_list_mutex; + os::MultiWaitType deferred_list; private: - virtual void RegisterSessionToWaitList(ServerSession *session) override final; - void RegisterToWaitList(os::WaitableHolderType *holder); - void ProcessWaitList(); + virtual void RegisterServerSessionToWait(ServerSession *session) override final; + void LinkToDeferredList(os::MultiWaitHolderType *holder); + void LinkDeferred(); bool WaitAndProcessImpl(); - Result ProcessForServer(os::WaitableHolderType *holder); - Result ProcessForMitmServer(os::WaitableHolderType *holder); - Result ProcessForSession(os::WaitableHolderType *holder); + Result ProcessForServer(os::MultiWaitHolderType *holder); + Result ProcessForMitmServer(os::MultiWaitHolderType *holder); + Result ProcessForSession(os::MultiWaitHolderType *holder); void RegisterServerImpl(Server *server, Handle port_handle, bool is_mitm_server) { server->port_handle = port_handle; - hipc::AttachWaitableHolderForAccept(server, port_handle); + hipc::AttachMultiWaitHolderForAccept(server, port_handle); server->is_mitm_server = is_mitm_server; if (is_mitm_server) { /* Mitm server. */ - os::SetWaitableHolderUserData(server, static_cast(UserDataTag::MitmServer)); + os::SetMultiWaitHolderUserData(server, static_cast(UserDataTag::MitmServer)); } else { /* Non-mitm server. */ - os::SetWaitableHolderUserData(server, static_cast(UserDataTag::Server)); + os::SetMultiWaitHolderUserData(server, static_cast(UserDataTag::Server)); } - os::LinkWaitableHolder(std::addressof(this->waitable_manager), server); + os::LinkMultiWaitHolder(std::addressof(this->multi_wait), server); } void RegisterServerImpl(int index, cmif::ServiceObjectHolder &&static_holder, Handle port_handle, bool is_mitm_server) { @@ -192,15 +192,16 @@ namespace ams::sf::hipc { ServerManagerBase(DomainEntryStorage *entry_storage, size_t entry_count) : ServerDomainSessionManager(entry_storage, entry_count), request_stop_event(os::EventClearMode_ManualClear), notify_event(os::EventClearMode_ManualClear), - waitable_selection_mutex(), waitlist_mutex() + selection_mutex(), deferred_list_mutex() { - /* Link waitables. */ - os::InitializeWaitableManager(std::addressof(this->waitable_manager)); - os::InitializeWaitableHolder(std::addressof(this->request_stop_event_holder), this->request_stop_event.GetBase()); - os::LinkWaitableHolder(std::addressof(this->waitable_manager), std::addressof(this->request_stop_event_holder)); - os::InitializeWaitableHolder(std::addressof(this->notify_event_holder), this->notify_event.GetBase()); - os::LinkWaitableHolder(std::addressof(this->waitable_manager), std::addressof(this->notify_event_holder)); - os::InitializeWaitableManager(std::addressof(this->waitlist)); + /* Link multi-wait holders. */ + os::InitializeMultiWait(std::addressof(this->multi_wait)); + os::InitializeMultiWaitHolder(std::addressof(this->request_stop_event_holder), this->request_stop_event.GetBase()); + os::LinkMultiWaitHolder(std::addressof(this->multi_wait), std::addressof(this->request_stop_event_holder)); + os::InitializeMultiWaitHolder(std::addressof(this->notify_event_holder), this->notify_event.GetBase()); + os::LinkMultiWaitHolder(std::addressof(this->multi_wait), std::addressof(this->notify_event_holder)); + + os::InitializeMultiWait(std::addressof(this->deferred_list)); } template @@ -227,13 +228,13 @@ namespace ams::sf::hipc { } /* Processing. */ - os::WaitableHolderType *WaitSignaled(); + os::MultiWaitHolderType *WaitSignaled(); void ResumeProcessing(); void RequestStopProcessing(); - void AddUserWaitableHolder(os::WaitableHolderType *waitable); + void AddUserMultiWaitHolder(os::MultiWaitHolderType *holder); - Result Process(os::WaitableHolderType *waitable); + Result Process(os::MultiWaitHolderType *holder); void WaitAndProcess(); void LoopProcess(); }; @@ -324,8 +325,8 @@ namespace ams::sf::hipc { const size_t index = this->GetServerIndex(server); AMS_ABORT_UNLESS(this->server_allocated[index]); { - os::UnlinkWaitableHolder(server); - os::FinalizeWaitableHolder(server); + os::UnlinkMultiWaitHolder(server); + os::FinalizeMultiWaitHolder(server); if (server->service_managed) { if (server->is_mitm_server) { R_ABORT_UNLESS(sm::mitm::UninstallMitm(server->service_name)); diff --git a/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_session_manager.hpp b/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_session_manager.hpp index 7d9f4e4da..72778b417 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_session_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_session_manager.hpp @@ -38,7 +38,7 @@ namespace ams::sf::hipc { } - class ServerSession : public os::WaitableHolderType { + class ServerSession : public os::MultiWaitHolderType { friend class ServerSessionManager; friend class ServerManagerBase; friend class impl::HipcManagerImpl; @@ -54,7 +54,7 @@ namespace ams::sf::hipc { bool has_received; public: ServerSession(Handle h, cmif::ServiceObjectHolder &&obj) : srv_obj_holder(std::move(obj)), session_handle(h) { - hipc::AttachWaitableHolderForReply(this, h); + hipc::AttachMultiWaitHolderForReply(this, h); this->is_closed = false; this->has_received = false; this->forward_service = nullptr; @@ -62,7 +62,7 @@ namespace ams::sf::hipc { } ServerSession(Handle h, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) : srv_obj_holder(std::move(obj)), session_handle(h) { - hipc::AttachWaitableHolderForReply(this, h); + hipc::AttachMultiWaitHolderForReply(this, h); this->is_closed = false; this->has_received = false; this->forward_service = std::move(fsrv); @@ -105,7 +105,7 @@ namespace ams::sf::hipc { void DestroySession(ServerSession *session); Result ProcessRequestImpl(ServerSession *session, const cmif::PointerAndSize &in_message, const cmif::PointerAndSize &out_message); - virtual void RegisterSessionToWaitList(ServerSession *session) = 0; + virtual void RegisterServerSessionToWait(ServerSession *session) = 0; protected: Result DispatchRequest(cmif::ServiceObjectHolder &&obj, ServerSession *session, const cmif::PointerAndSize &in_message, const cmif::PointerAndSize &out_message); virtual Result DispatchManagerRequest(ServerSession *session, const cmif::PointerAndSize &in_message, const cmif::PointerAndSize &out_message); diff --git a/libraries/libstratosphere/include/stratosphere/tipc/tipc_waitable_object.hpp b/libraries/libstratosphere/include/stratosphere/tipc/tipc_object_holder.hpp similarity index 94% rename from libraries/libstratosphere/include/stratosphere/tipc/tipc_waitable_object.hpp rename to libraries/libstratosphere/include/stratosphere/tipc/tipc_object_holder.hpp index cddce48fa..dff3f967f 100644 --- a/libraries/libstratosphere/include/stratosphere/tipc/tipc_waitable_object.hpp +++ b/libraries/libstratosphere/include/stratosphere/tipc/tipc_object_holder.hpp @@ -20,7 +20,7 @@ namespace ams::tipc { - class WaitableObject { + class ObjectHolder { public: enum ObjectType : u8 { ObjectType_Invalid = 0, @@ -44,7 +44,7 @@ namespace ams::tipc { m_object = object; } public: - constexpr inline WaitableObject() : m_handle(svc::InvalidHandle), m_type(ObjectType_Invalid), m_managed(false), m_object(nullptr) { /* ... */ } + constexpr inline ObjectHolder() : m_handle(svc::InvalidHandle), m_type(ObjectType_Invalid), m_managed(false), m_object(nullptr) { /* ... */ } void InitializeAsPort(svc::Handle handle) { /* NOTE: Nintendo sets ports as managed, but this will cause a nullptr-deref if one is ever closed. */ diff --git a/libraries/libstratosphere/include/stratosphere/tipc/tipc_object_manager.hpp b/libraries/libstratosphere/include/stratosphere/tipc/tipc_object_manager.hpp index a0b8f9942..165a87e25 100644 --- a/libraries/libstratosphere/include/stratosphere/tipc/tipc_object_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/tipc/tipc_object_manager.hpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include namespace ams::tipc { @@ -28,14 +28,14 @@ namespace ams::tipc { class ObjectManagerBase { protected: struct Entry { - util::TypedStorage object; - os::WaitableHolderType waitable_holder; + util::TypedStorage object; + os::MultiWaitHolderType multi_wait_holder; }; private: os::SdkMutex m_mutex{}; Entry *m_entries_start{}; Entry *m_entries_end{}; - os::WaitableManagerType *m_waitable_manager{}; + os::MultiWaitType *m_multi_wait{}; private: Entry *FindEntry(svc::Handle handle) { for (Entry *cur = m_entries_start; cur != m_entries_end; ++cur) { @@ -46,9 +46,9 @@ namespace ams::tipc { return nullptr; } - Entry *FindEntry(os::WaitableHolderType *holder) { + Entry *FindEntry(os::MultiWaitHolderType *holder) { for (Entry *cur = m_entries_start; cur != m_entries_end; ++cur) { - if (std::addressof(cur->waitable_holder) == holder) { + if (std::addressof(cur->multi_wait_holder) == holder) { return cur; } } @@ -57,9 +57,9 @@ namespace ams::tipc { public: constexpr ObjectManagerBase() = default; - void InitializeImpl(os::WaitableManagerType *manager, Entry *entries, size_t max_objects) { - /* Set our waitable manager. */ - m_waitable_manager = manager; + void InitializeImpl(os::MultiWaitType *multi_wait, Entry *entries, size_t max_objects) { + /* Set our multi wait. */ + m_multi_wait = multi_wait; /* Setup entry pointers. */ m_entries_start = entries; @@ -71,7 +71,7 @@ namespace ams::tipc { } } - void AddObject(WaitableObject &object) { + void AddObject(ObjectHolder &object) { /* Lock ourselves. */ std::scoped_lock lk(m_mutex); @@ -83,8 +83,8 @@ namespace ams::tipc { GetReference(entry->object) = object; /* Setup the entry's holder. */ - os::InitializeWaitableHolder(std::addressof(entry->waitable_holder), object.GetHandle()); - os::LinkWaitableHolder(m_waitable_manager, std::addressof(entry->waitable_holder)); + os::InitializeMultiWaitHolder(std::addressof(entry->multi_wait_holder), object.GetHandle()); + os::LinkMultiWaitHolder(m_multi_wait, std::addressof(entry->multi_wait_holder)); } void CloseObject(svc::Handle handle) { @@ -96,21 +96,21 @@ namespace ams::tipc { AMS_ABORT_UNLESS(entry != nullptr); /* Finalize the entry's holder. */ - os::UnlinkWaitableHolder(std::addressof(entry->waitable_holder)); - os::FinalizeWaitableHolder(std::addressof(entry->waitable_holder)); + os::UnlinkMultiWaitHolder(std::addressof(entry->multi_wait_holder)); + os::FinalizeMultiWaitHolder(std::addressof(entry->multi_wait_holder)); /* Destroy the object. */ GetReference(entry->object).Destroy(); } - Result ReplyAndReceive(os::WaitableHolderType **out_holder, WaitableObject *out_object, svc::Handle reply_target, os::WaitableManagerType *manager) { + Result ReplyAndReceive(os::MultiWaitHolderType **out_holder, ObjectHolder *out_object, svc::Handle reply_target, os::MultiWaitType *multi_wait) { /* Declare signaled holder for processing ahead of time. */ - os::WaitableHolderType *signaled_holder; + os::MultiWaitHolderType *signaled_holder; /* Reply and receive until we get a newly signaled target. */ - Result result = os::SdkReplyAndReceive(out_holder, reply_target, manager); + Result result = os::SdkReplyAndReceive(out_holder, reply_target, multi_wait); for (signaled_holder = *out_holder; signaled_holder == nullptr; signaled_holder = *out_holder) { - result = os::SdkReplyAndReceive(out_holder, svc::InvalidHandle, manager); + result = os::SdkReplyAndReceive(out_holder, svc::InvalidHandle, multi_wait); } /* Find the entry matching the signaled holder. */ @@ -140,7 +140,7 @@ namespace ams::tipc { return ResultSuccess(); } - Result ProcessRequest(WaitableObject &object) { + Result ProcessRequest(ObjectHolder &object) { /* Get the method id. */ const auto method_id = svc::ipc::MessageBuffer::MessageHeader(svc::ipc::MessageBuffer(svc::ipc::GetMessageBuffer())).GetTag(); @@ -176,8 +176,8 @@ namespace ams::tipc { public: constexpr ObjectManager() = default; - void Initialize(os::WaitableManagerType *manager) { - this->InitializeImpl(manager, m_entries_storage, MaxObjects); + void Initialize(os::MultiWaitType *multi_wait) { + this->InitializeImpl(multi_wait, m_entries_storage, MaxObjects); } }; diff --git a/libraries/libstratosphere/include/stratosphere/tipc/tipc_server_manager.hpp b/libraries/libstratosphere/include/stratosphere/tipc/tipc_server_manager.hpp index 33df54dc5..3c2b17f1b 100644 --- a/libraries/libstratosphere/include/stratosphere/tipc/tipc_server_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/tipc/tipc_server_manager.hpp @@ -36,7 +36,7 @@ namespace ams::tipc { class PortManagerInterface { public: - virtual Result ProcessRequest(WaitableObject &object) = 0; + virtual Result ProcessRequest(ObjectHolder &object) = 0; }; template @@ -97,18 +97,18 @@ namespace ams::tipc { s32 m_id; std::atomic m_num_sessions; s32 m_port_number; - os::WaitableManagerType m_waitable_manager; + os::MultiWaitType m_multi_wait; DeferralManagerType m_deferral_manager; os::MessageQueueType m_message_queue; - os::WaitableHolderType m_message_queue_holder; + os::MultiWaitHolderType m_message_queue_holder; uintptr_t m_message_queue_storage[MaxSessions]; ObjectManagerBase *m_object_manager; ServerManagerImpl *m_server_manager; public: - PortManagerBase() : m_id(), m_num_sessions(), m_port_number(), m_waitable_manager(), m_deferral_manager(), m_message_queue(), m_message_queue_holder(), m_message_queue_storage(), m_object_manager(), m_server_manager() { + PortManagerBase() : m_id(), m_num_sessions(), m_port_number(), m_multi_wait(), m_deferral_manager(), m_message_queue(), m_message_queue_holder(), m_message_queue_storage(), m_object_manager(), m_server_manager() { /* Setup our message queue. */ os::InitializeMessageQueue(std::addressof(m_message_queue), m_message_queue_storage, util::size(m_message_queue_storage)); - os::InitializeWaitableHolder(std::addressof(m_message_queue_holder), std::addressof(m_message_queue), os::MessageQueueWaitType::ForNotEmpty); + os::InitializeMultiWaitHolder(std::addressof(m_message_queue_holder), std::addressof(m_message_queue), os::MessageQueueWaitType::ForNotEmpty); } constexpr s32 GetPortIndex() const { @@ -133,9 +133,9 @@ namespace ams::tipc { /* Reset our session count. */ m_num_sessions = 0; - /* Initialize our waitable manager. */ - os::InitializeWaitableManager(std::addressof(m_waitable_manager)); - os::LinkWaitableHolder(std::addressof(m_waitable_manager), std::addressof(m_message_queue_holder)); + /* Initialize our multi wait. */ + os::InitializeMultiWait(std::addressof(m_multi_wait)); + os::LinkMultiWaitHolder(std::addressof(m_multi_wait), std::addressof(m_message_queue_holder)); /* Initialize our object manager. */ m_object_manager = manager; @@ -145,8 +145,8 @@ namespace ams::tipc { /* Set our port number. */ this->m_port_number = index; - /* Create a waitable object for the port. */ - tipc::WaitableObject object; + /* Create an object holder for the port. */ + tipc::ObjectHolder object; /* Setup the object. */ object.InitializeAsPort(port_handle); @@ -155,7 +155,7 @@ namespace ams::tipc { m_object_manager->AddObject(object); } - virtual Result ProcessRequest(WaitableObject &object) override { + virtual Result ProcessRequest(ObjectHolder &object) override { /* Process the request, this must succeed because we succeeded when deferring earlier. */ R_ABORT_UNLESS(m_object_manager->ProcessRequest(object)); @@ -168,13 +168,13 @@ namespace ams::tipc { return m_object_manager->Reply(object.GetHandle()); } - Result ReplyAndReceive(os::WaitableHolderType **out_holder, WaitableObject *out_object, svc::Handle reply_target) { - return m_object_manager->ReplyAndReceive(out_holder, out_object, reply_target, std::addressof(m_waitable_manager)); + Result ReplyAndReceive(os::MultiWaitHolderType **out_holder, ObjectHolder *out_object, svc::Handle reply_target) { + return m_object_manager->ReplyAndReceive(out_holder, out_object, reply_target, std::addressof(m_multi_wait)); } void AddSession(svc::Handle session_handle, tipc::ServiceObjectBase *service_object) { - /* Create a waitable object for the session. */ - tipc::WaitableObject object; + /* Create an object holder for the session. */ + tipc::ObjectHolder object; /* Setup the object. */ object.InitializeAsSession(session_handle, true, service_object); @@ -219,7 +219,7 @@ namespace ams::tipc { } } - void CloseSession(WaitableObject &object) { + void CloseSession(ObjectHolder &object) { /* Get the object's handle. */ const auto handle = object.GetHandle(); @@ -233,7 +233,7 @@ namespace ams::tipc { --m_num_sessions; } - void CloseSessionIfNecessary(WaitableObject &object, bool necessary) { + void CloseSessionIfNecessary(ObjectHolder &object, bool necessary) { if (necessary) { /* Get the object's handle. */ const auto handle = object.GetHandle(); @@ -261,7 +261,7 @@ namespace ams::tipc { } } - void ProcessRegisterRetry(WaitableObject &object) { + void ProcessRegisterRetry(ObjectHolder &object) { if constexpr (IsDeferralSupported) { /* Acquire exclusive server manager access. */ std::scoped_lock lk(m_server_manager->GetMutex()); @@ -342,7 +342,7 @@ namespace ams::tipc { this->InitializeBase(id, sm, std::addressof(m_object_manager_impl)); /* Initialize our object manager. */ - m_object_manager_impl.Initialize(std::addressof(this->m_waitable_manager)); + m_object_manager_impl.Initialize(std::addressof(this->m_multi_wait)); } }; @@ -517,8 +517,8 @@ namespace ams::tipc { svc::Handle reply_target = svc::InvalidHandle; while (true) { /* Reply to our pending request, and receive a new one. */ - os::WaitableHolderType *signaled_holder = nullptr; - tipc::WaitableObject signaled_object{}; + os::MultiWaitHolderType *signaled_holder = nullptr; + tipc::ObjectHolder signaled_object{}; R_TRY_CATCH(port_manager.ReplyAndReceive(std::addressof(signaled_holder), std::addressof(signaled_object), reply_target)) { R_CATCH(os::ResultSessionClosedForReceive, os::ResultReceiveListBroken) { /* Close the object and continue. */ @@ -533,7 +533,7 @@ namespace ams::tipc { if (signaled_holder == nullptr) { /* A session was signaled, accessible via signaled_object. */ switch (signaled_object.GetType()) { - case WaitableObject::ObjectType_Port: + case ObjectHolder::ObjectType_Port: { /* Try to accept a new session */ svc::Handle session_handle; @@ -545,7 +545,7 @@ namespace ams::tipc { reply_target = svc::InvalidHandle; } break; - case WaitableObject::ObjectType_Session: + case ObjectHolder::ObjectType_Session: { /* Process the request */ const Result process_result = port_manager.GetObjectManager()->ProcessRequest(signaled_object); diff --git a/libraries/libstratosphere/source/ddsf/ddsf_event_handler.cpp b/libraries/libstratosphere/source/ddsf/ddsf_event_handler.cpp index 490d26f2e..acc91c26d 100644 --- a/libraries/libstratosphere/source/ddsf/ddsf_event_handler.cpp +++ b/libraries/libstratosphere/source/ddsf/ddsf_event_handler.cpp @@ -42,10 +42,10 @@ namespace ams::ddsf { return; } - /* Initialize waitable manager/holder. */ - os::InitializeWaitableManager(std::addressof(this->waitable_manager)); - os::InitializeWaitableHolder(std::addressof(this->loop_control_event_holder), this->loop_control_event.GetBase()); - os::LinkWaitableHolder(std::addressof(this->waitable_manager), std::addressof(this->loop_control_event_holder)); + /* Initialize multi wait/holder. */ + os::InitializeMultiWait(std::addressof(this->multi_wait)); + os::InitializeMultiWaitHolder(std::addressof(this->loop_control_event_holder), this->loop_control_event.GetBase()); + os::LinkMultiWaitHolder(std::addressof(this->multi_wait), std::addressof(this->loop_control_event_holder)); this->is_initialized = true; } @@ -58,10 +58,10 @@ namespace ams::ddsf { return; } - /* Finalize waitable manager/holder. */ - os::UnlinkWaitableHolder(std::addressof(this->loop_control_event_holder)); - os::FinalizeWaitableHolder(std::addressof(this->loop_control_event_holder)); - os::FinalizeWaitableManager(std::addressof(this->waitable_manager)); + /* Finalize multi wait/holder. */ + os::UnlinkMultiWaitHolder(std::addressof(this->loop_control_event_holder)); + os::FinalizeMultiWaitHolder(std::addressof(this->loop_control_event_holder)); + os::FinalizeMultiWait(std::addressof(this->multi_wait)); this->is_initialized = false; } @@ -94,7 +94,7 @@ namespace ams::ddsf { /* Process the command. */ switch (params->command) { case LoopControlCommand::Register: - params->target->Link(std::addressof(this->waitable_manager)); + params->target->Link(std::addressof(this->multi_wait)); break; case LoopControlCommand::Unregister: params->target->Unlink(); @@ -180,7 +180,7 @@ namespace ams::ddsf { bool should_terminate = false; while (!should_terminate) { /* Wait for a holder to be signaled. */ - os::WaitableHolderType *event_holder = os::WaitAny(std::addressof(this->waitable_manager)); + os::MultiWaitHolderType *event_holder = os::WaitAny(std::addressof(this->multi_wait)); AMS_ASSERT(event_holder != nullptr); /* Check if we have a request to handle. */ diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_service.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_service.cpp index 1eec3c395..6ca76e4fa 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_service.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_service.cpp @@ -97,13 +97,13 @@ namespace ams::erpt::srv { psc::PmModule pm_module; psc::PmState pm_state; psc::PmFlagSet pm_flags; - os::WaitableHolderType module_event_holder; + os::MultiWaitHolderType module_event_holder; R_ABORT_UNLESS(pm_module.Initialize(psc::PmModuleId_Erpt, dependencies, util::size(dependencies), os::EventClearMode_ManualClear)); - os::InitializeWaitableHolder(std::addressof(module_event_holder), pm_module.GetEventPointer()->GetBase()); - os::SetWaitableHolderUserData(std::addressof(module_event_holder), static_cast(psc::PmModuleId_Erpt)); - this->AddUserWaitableHolder(std::addressof(module_event_holder)); + os::InitializeMultiWaitHolder(std::addressof(module_event_holder), pm_module.GetEventPointer()->GetBase()); + os::SetMultiWaitHolderUserData(std::addressof(module_event_holder), static_cast(psc::PmModuleId_Erpt)); + this->AddUserMultiWaitHolder(std::addressof(module_event_holder)); while (true) { /* NOTE: Nintendo checks the user holder data to determine what's signaled, we will prefer to just check the address. */ @@ -131,7 +131,7 @@ namespace ams::erpt::srv { } else { AMS_ASSERT(false); } - this->AddUserWaitableHolder(signaled_holder); + this->AddUserMultiWaitHolder(signaled_holder); } } } diff --git a/libraries/libstratosphere/source/htclow/driver/htclow_usb_impl.cpp b/libraries/libstratosphere/source/htclow/driver/htclow_usb_impl.cpp index ab769752b..a9f8ed868 100644 --- a/libraries/libstratosphere/source/htclow/driver/htclow_usb_impl.cpp +++ b/libraries/libstratosphere/source/htclow/driver/htclow_usb_impl.cpp @@ -276,22 +276,22 @@ namespace ams::htclow::driver { /* Get the state change event. */ os::SystemEventType *state_change_event = g_ds_client.GetStateChangeEvent(); - /* Setup waitable manager. */ - os::WaitableManagerType manager; - os::InitializeWaitableManager(std::addressof(manager)); + /* Setup multi wait. */ + os::MultiWaitType multi_wait; + os::InitializeMultiWait(std::addressof(multi_wait)); - /* Link waitable holders. */ - os::WaitableHolderType state_change_holder; - os::WaitableHolderType break_holder; - os::InitializeWaitableHolder(std::addressof(state_change_holder), state_change_event); - os::LinkWaitableHolder(std::addressof(manager), std::addressof(state_change_holder)); - os::InitializeWaitableHolder(std::addressof(break_holder), g_usb_break_event.GetBase()); - os::LinkWaitableHolder(std::addressof(manager), std::addressof(break_holder)); + /* Link multi wait holders. */ + os::MultiWaitHolderType state_change_holder; + os::MultiWaitHolderType break_holder; + os::InitializeMultiWaitHolder(std::addressof(state_change_holder), state_change_event); + os::LinkMultiWaitHolder(std::addressof(multi_wait), std::addressof(state_change_holder)); + os::InitializeMultiWaitHolder(std::addressof(break_holder), g_usb_break_event.GetBase()); + os::LinkMultiWaitHolder(std::addressof(multi_wait), std::addressof(break_holder)); /* Loop forever. */ while (true) { /* If we should break, do so. */ - if (os::WaitAny(std::addressof(manager)) == std::addressof(break_holder)) { + if (os::WaitAny(std::addressof(multi_wait)) == std::addressof(break_holder)) { break; } @@ -320,12 +320,12 @@ namespace ams::htclow::driver { g_usb_break_event.Clear(); /* Unlink all holders. */ - os::UnlinkAllWaitableHolder(std::addressof(manager)); + os::UnlinkAllMultiWaitHolder(std::addressof(multi_wait)); - /* Finalize the waitable holders and manager. */ - os::FinalizeWaitableHolder(std::addressof(break_holder)); - os::FinalizeWaitableHolder(std::addressof(state_change_holder)); - os::FinalizeWaitableManager(std::addressof(manager)); + /* Finalize the multi wait/holders. */ + os::FinalizeMultiWaitHolder(std::addressof(break_holder)); + os::FinalizeMultiWaitHolder(std::addressof(state_change_holder)); + os::FinalizeMultiWait(std::addressof(multi_wait)); } } diff --git a/libraries/libstratosphere/source/lm/srv/lm_ipc_server.cpp b/libraries/libstratosphere/source/lm/srv/lm_ipc_server.cpp index 6a9a14cb1..e668577f7 100644 --- a/libraries/libstratosphere/source/lm/srv/lm_ipc_server.cpp +++ b/libraries/libstratosphere/source/lm/srv/lm_ipc_server.cpp @@ -42,7 +42,7 @@ namespace ams::lm::srv { constinit util::TypedStorage g_pm_module_storage; constinit psc::PmModule *g_pm_module; - constinit os::WaitableHolderType g_pm_module_holder; + constinit os::MultiWaitHolderType g_pm_module_holder; constexpr const psc::PmModuleId PmModuleDependencies[] = { psc::PmModuleId_TmaHostIo, psc::PmModuleId_Fs }; @@ -67,15 +67,15 @@ namespace ams::lm::srv { g_pm_module = util::ConstructAt(g_pm_module_storage); R_ABORT_UNLESS(g_pm_module->Initialize(psc::PmModuleId_Lm, PmModuleDependencies, util::size(PmModuleDependencies), os::EventClearMode_ManualClear)); - /* Create the psc module waitable holder. */ - os::InitializeWaitableHolder(std::addressof(g_pm_module_holder), g_pm_module->GetEventPointer()->GetBase()); - os::SetWaitableHolderUserData(std::addressof(g_pm_module_holder), psc::PmModuleId_Lm); + /* Create the psc module multi wait holder. */ + os::InitializeMultiWaitHolder(std::addressof(g_pm_module_holder), g_pm_module->GetEventPointer()->GetBase()); + os::SetMultiWaitHolderUserData(std::addressof(g_pm_module_holder), psc::PmModuleId_Lm); /* Create the server manager. */ g_server_manager = util::ConstructAt(g_server_manager_storage); /* Add the pm module holder. */ - g_server_manager->AddUserWaitableHolder(std::addressof(g_pm_module_holder)); + g_server_manager->AddUserMultiWaitHolder(std::addressof(g_pm_module_holder)); /* Create services. */ R_ABORT_UNLESS(g_server_manager->RegisterObjectForServer(g_log_service_object.GetShared(), LogServiceName, LogSessionCountMax)); @@ -100,7 +100,7 @@ namespace ams::lm::srv { } else { /* If pm module, clear the event. */ g_pm_module->GetEventPointer()->Clear(); - g_server_manager->AddUserWaitableHolder(signaled_holder); + g_server_manager->AddUserMultiWaitHolder(signaled_holder); /* Get the power state. */ psc::PmState pm_state; diff --git a/libraries/libstratosphere/source/os/impl/os_inter_process_event.cpp b/libraries/libstratosphere/source/os/impl/os_inter_process_event.cpp index 2de8a5a31..c15754a58 100644 --- a/libraries/libstratosphere/source/os/impl/os_inter_process_event.cpp +++ b/libraries/libstratosphere/source/os/impl/os_inter_process_event.cpp @@ -16,7 +16,7 @@ #include #include "os_inter_process_event.hpp" #include "os_inter_process_event_impl.hpp" -#include "os_waitable_object_list.hpp" +#include "os_multiple_wait_object_list.hpp" namespace ams::os::impl { @@ -33,7 +33,7 @@ namespace ams::os::impl { event->auto_clear = (clear_mode == EventClearMode_AutoClear); /* Create the waitlist node. */ - util::ConstructAt(event->waitable_object_list_storage); + util::ConstructAt(event->multi_wait_object_list_storage); /* Set state. */ event->state = InterProcessEventType::State_Initialized; @@ -71,7 +71,7 @@ namespace ams::os::impl { } /* Destroy the waitlist. */ - util::DestroyAt(event->waitable_object_list_storage); + util::DestroyAt(event->multi_wait_object_list_storage); } void AttachInterProcessEvent(InterProcessEventType *event, Handle read_handle, bool read_handle_managed, Handle write_handle, bool write_handle_managed, EventClearMode clear_mode) { diff --git a/libraries/libstratosphere/source/os/impl/os_inter_process_event.hpp b/libraries/libstratosphere/source/os/impl/os_inter_process_event.hpp index 0b5ee902e..aeca0fbf7 100644 --- a/libraries/libstratosphere/source/os/impl/os_inter_process_event.hpp +++ b/libraries/libstratosphere/source/os/impl/os_inter_process_event.hpp @@ -36,6 +36,6 @@ namespace ams::os::impl { Handle GetReadableHandleOfInterProcessEvent(const InterProcessEventType *event); Handle GetWritableHandleOfInterProcessEvent(const InterProcessEventType *event); - void InitializeWaitableHolder(WaitableHolderType *waitable_holder, InterProcessEventType *event); + void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, InterProcessEventType *event); } diff --git a/libraries/libstratosphere/source/os/impl/os_waitable_holder_base.hpp b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_base.hpp similarity index 70% rename from libraries/libstratosphere/source/os/impl/os_waitable_holder_base.hpp rename to libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_base.hpp index c6c098f96..b9761e7e0 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_holder_base.hpp +++ b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_base.hpp @@ -18,21 +18,21 @@ namespace ams::os::impl { - class WaitableObjectList; - class WaitableManagerImpl; + class MultiWaitObjectList; + class MultiWaitImpl; - class WaitableHolderBase { + class MultiWaitHolderBase { private: - WaitableManagerImpl *manager = nullptr; + MultiWaitImpl *multi_wait = nullptr; public: - util::IntrusiveListNode manager_node; + util::IntrusiveListNode multi_wait_node; util::IntrusiveListNode object_list_node; public: - /* Gets whether the held waitable is currently signaled. */ + /* Gets whether the held object is currently signaled. */ virtual TriBool IsSignaled() const = 0; - /* Adds to manager's object list, returns is signaled. */ + /* Adds to multi wait's object list, returns is signaled. */ virtual TriBool LinkToObjectList() = 0; - /* Removes from the manager's object list. */ + /* Removes from the multi wait's object list. */ virtual void UnlinkFromObjectList() = 0; /* Gets handle to output, returns INVALID_HANDLE on failure. */ virtual Handle GetHandle() const = 0; @@ -41,21 +41,21 @@ namespace ams::os::impl { return TimeSpan::FromNanoSeconds(std::numeric_limits::max()); } - /* Interface with manager. */ - void SetManager(WaitableManagerImpl *m) { - this->manager = m; + /* Interface with multi wait. */ + void SetMultiWait(MultiWaitImpl *m) { + this->multi_wait = m; } - WaitableManagerImpl *GetManager() const { - return this->manager; + MultiWaitImpl *GetMultiWait() const { + return this->multi_wait; } - bool IsLinkedToManager() const { - return this->manager != nullptr; + bool IsLinked() const { + return this->multi_wait != nullptr; } }; - class WaitableHolderOfUserObject : public WaitableHolderBase { + class MultiWaitHolderOfUserObject : public MultiWaitHolderBase { public: /* All user objects have no handle to wait on. */ virtual Handle GetHandle() const override final { @@ -63,7 +63,7 @@ namespace ams::os::impl { } }; - class WaitableHolderOfKernelObject : public WaitableHolderBase { + class MultiWaitHolderOfKernelObject : public MultiWaitHolderBase { public: /* All kernel objects have native handles, and thus don't have object list semantics. */ virtual TriBool LinkToObjectList() override final { diff --git a/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_impl.hpp b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_impl.hpp new file mode 100644 index 000000000..844909d9a --- /dev/null +++ b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_impl.hpp @@ -0,0 +1,59 @@ +/* + * 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 "os_multiple_wait_holder_of_handle.hpp" +#include "os_multiple_wait_holder_of_event.hpp" +#include "os_multiple_wait_holder_of_inter_process_event.hpp" +#include "os_multiple_wait_holder_of_interrupt_event.hpp" +#include "os_multiple_wait_holder_of_timer_event.hpp" +#include "os_multiple_wait_holder_of_thread.hpp" +#include "os_multiple_wait_holder_of_semaphore.hpp" +#include "os_multiple_wait_holder_of_message_queue.hpp" + +namespace ams::os::impl { + + struct MultiWaitHolderImpl { + union { + util::TypedStorage holder_of_handle_storage; + util::TypedStorage holder_of_event_storage; + util::TypedStorage holder_of_inter_process_event_storage; + util::TypedStorage holder_of_interrupt_event_storage; + util::TypedStorage holder_of_timer_event_storage; + util::TypedStorage holder_of_thread_storage; + util::TypedStorage holder_of_semaphore_storage; + util::TypedStorage holder_of_mq_for_not_full_storage; + util::TypedStorage holder_of_mq_for_not_empty_storage; + }; + }; + + #define CHECK_HOLDER(T) \ + static_assert(std::is_base_of<::ams::os::impl::MultiWaitHolderBase, T>::value && std::is_trivially_destructible::value, #T) + + CHECK_HOLDER(MultiWaitHolderOfHandle); + CHECK_HOLDER(MultiWaitHolderOfEvent); + CHECK_HOLDER(MultiWaitHolderOfInterProcessEvent); + CHECK_HOLDER(MultiWaitHolderOfInterruptEvent); + CHECK_HOLDER(MultiWaitHolderOfTimerEvent); + CHECK_HOLDER(MultiWaitHolderOfThread); + CHECK_HOLDER(MultiWaitHolderOfSemaphore); + CHECK_HOLDER(MultiWaitHolderOfMessageQueueForNotFull); + CHECK_HOLDER(MultiWaitHolderOfMessageQueueForNotEmpty); + + #undef CHECK_HOLDER + + static_assert(std::is_trivial::value && std::is_trivially_destructible::value); + static_assert(sizeof(MultiWaitHolderImpl) == sizeof(os::MultiWaitHolderType::impl_storage)); +} diff --git a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_event.hpp b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_event.hpp similarity index 77% rename from libraries/libstratosphere/source/os/impl/os_waitable_holder_of_event.hpp rename to libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_event.hpp index 8b203c4aa..574db2ecb 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_event.hpp +++ b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_event.hpp @@ -14,12 +14,12 @@ * along with this program. If not, see . */ #pragma once -#include "os_waitable_holder_base.hpp" -#include "os_waitable_object_list.hpp" +#include "os_multiple_wait_holder_base.hpp" +#include "os_multiple_wait_object_list.hpp" namespace ams::os::impl { - class WaitableHolderOfEvent : public WaitableHolderOfUserObject { + class MultiWaitHolderOfEvent : public MultiWaitHolderOfUserObject { private: EventType *event; private: @@ -27,7 +27,7 @@ namespace ams::os::impl { return this->event->signaled ? TriBool::True : TriBool::False; } public: - explicit WaitableHolderOfEvent(EventType *e) : event(e) { /* ... */ } + explicit MultiWaitHolderOfEvent(EventType *e) : event(e) { /* ... */ } /* IsSignaled, Link, Unlink implemented. */ virtual TriBool IsSignaled() const override { @@ -38,14 +38,14 @@ namespace ams::os::impl { virtual TriBool LinkToObjectList() override { std::scoped_lock lk(GetReference(this->event->cs_event)); - GetReference(this->event->waitable_object_list_storage).LinkWaitableHolder(*this); + GetReference(this->event->multi_wait_object_list_storage).LinkMultiWaitHolder(*this); return this->IsSignaledImpl(); } virtual void UnlinkFromObjectList() override { std::scoped_lock lk(GetReference(this->event->cs_event)); - GetReference(this->event->waitable_object_list_storage).UnlinkWaitableHolder(*this); + GetReference(this->event->multi_wait_object_list_storage).UnlinkMultiWaitHolder(*this); } }; diff --git a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_handle.hpp b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_handle.hpp similarity index 83% rename from libraries/libstratosphere/source/os/impl/os_waitable_holder_of_handle.hpp rename to libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_handle.hpp index 5e08cacad..a9e49b302 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_handle.hpp +++ b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_handle.hpp @@ -14,15 +14,15 @@ * along with this program. If not, see . */ #pragma once -#include "os_waitable_holder_base.hpp" +#include "os_multiple_wait_holder_base.hpp" namespace ams::os::impl { - class WaitableHolderOfHandle : public WaitableHolderOfKernelObject { + class MultiWaitHolderOfHandle : public MultiWaitHolderOfKernelObject { private: Handle handle; public: - explicit WaitableHolderOfHandle(Handle h) : handle(h) { /* ... */ } + explicit MultiWaitHolderOfHandle(Handle h) : handle(h) { /* ... */ } /* IsSignaled, GetHandle both implemented. */ virtual TriBool IsSignaled() const override { diff --git a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_inter_process_event.hpp b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_inter_process_event.hpp similarity index 82% rename from libraries/libstratosphere/source/os/impl/os_waitable_holder_of_inter_process_event.hpp rename to libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_inter_process_event.hpp index 3012da3eb..b780e2bcc 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_inter_process_event.hpp +++ b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_inter_process_event.hpp @@ -14,16 +14,16 @@ * along with this program. If not, see . */ #pragma once -#include "os_waitable_holder_base.hpp" +#include "os_multiple_wait_holder_base.hpp" #include "os_inter_process_event.hpp" namespace ams::os::impl { - class WaitableHolderOfInterProcessEvent : public WaitableHolderOfKernelObject { + class MultiWaitHolderOfInterProcessEvent : public MultiWaitHolderOfKernelObject { private: InterProcessEventType *event; public: - explicit WaitableHolderOfInterProcessEvent(InterProcessEventType *e) : event(e) { /* ... */ } + explicit MultiWaitHolderOfInterProcessEvent(InterProcessEventType *e) : event(e) { /* ... */ } /* IsSignaled, GetHandle both implemented. */ virtual TriBool IsSignaled() const override { diff --git a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_interrupt_event.cpp b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_interrupt_event.cpp similarity index 86% rename from libraries/libstratosphere/source/os/impl/os_waitable_holder_of_interrupt_event.cpp rename to libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_interrupt_event.cpp index e553f131c..5180ff3c6 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_interrupt_event.cpp +++ b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_interrupt_event.cpp @@ -14,12 +14,12 @@ * along with this program. If not, see . */ #include -#include "os_waitable_holder_of_interrupt_event.hpp" +#include "os_multiple_wait_holder_of_interrupt_event.hpp" #include "os_interrupt_event_impl.hpp" namespace ams::os::impl { - Handle WaitableHolderOfInterruptEvent::GetHandle() const { + Handle MultiWaitHolderOfInterruptEvent::GetHandle() const { return GetReference(event->impl).GetHandle(); } diff --git a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_interrupt_event.hpp b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_interrupt_event.hpp similarity index 81% rename from libraries/libstratosphere/source/os/impl/os_waitable_holder_of_interrupt_event.hpp rename to libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_interrupt_event.hpp index 10dcea933..628c9a3d4 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_interrupt_event.hpp +++ b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_interrupt_event.hpp @@ -14,15 +14,15 @@ * along with this program. If not, see . */ #pragma once -#include "os_waitable_holder_base.hpp" +#include "os_multiple_wait_holder_base.hpp" namespace ams::os::impl { - class WaitableHolderOfInterruptEvent : public WaitableHolderOfKernelObject { + class MultiWaitHolderOfInterruptEvent : public MultiWaitHolderOfKernelObject { private: InterruptEventType *event; public: - explicit WaitableHolderOfInterruptEvent(InterruptEventType *e) : event(e) { /* ... */ } + explicit MultiWaitHolderOfInterruptEvent(InterruptEventType *e) : event(e) { /* ... */ } /* IsSignaled, GetHandle both implemented. */ virtual TriBool IsSignaled() const override { diff --git a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_message_queue.hpp b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_message_queue.hpp similarity index 78% rename from libraries/libstratosphere/source/os/impl/os_waitable_holder_of_message_queue.hpp rename to libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_message_queue.hpp index bc5468399..2fb57ff87 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_message_queue.hpp +++ b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_message_queue.hpp @@ -14,13 +14,13 @@ * along with this program. If not, see . */ #pragma once -#include "os_waitable_holder_base.hpp" -#include "os_waitable_object_list.hpp" +#include "os_multiple_wait_holder_base.hpp" +#include "os_multiple_wait_object_list.hpp" namespace ams::os::impl { template - class WaitableHolderOfMessageQueue : public WaitableHolderOfUserObject { + class MultiWaitHolderOfMessageQueue : public MultiWaitHolderOfUserObject { static_assert(WaitType == MessageQueueWaitType::ForNotEmpty || WaitType == MessageQueueWaitType::ForNotFull); private: MessageQueueType *mq; @@ -37,7 +37,7 @@ namespace ams::os::impl { } } - constexpr inline WaitableObjectList &GetObjectList() const { + constexpr inline MultiWaitObjectList &GetObjectList() const { if constexpr (WaitType == MessageQueueWaitType::ForNotEmpty) { return GetReference(this->mq->waitlist_not_empty); } else if constexpr (WaitType == MessageQueueWaitType::ForNotFull) { @@ -47,7 +47,7 @@ namespace ams::os::impl { } } public: - explicit WaitableHolderOfMessageQueue(MessageQueueType *mq) : mq(mq) { /* ... */ } + explicit MultiWaitHolderOfMessageQueue(MessageQueueType *mq) : mq(mq) { /* ... */ } /* IsSignaled, Link, Unlink implemented. */ virtual TriBool IsSignaled() const override { @@ -58,18 +58,18 @@ namespace ams::os::impl { virtual TriBool LinkToObjectList() override { std::scoped_lock lk(GetReference(this->mq->cs_queue)); - this->GetObjectList().LinkWaitableHolder(*this); + this->GetObjectList().LinkMultiWaitHolder(*this); return this->IsSignaledImpl(); } virtual void UnlinkFromObjectList() override { std::scoped_lock lk(GetReference(this->mq->cs_queue)); - this->GetObjectList().UnlinkWaitableHolder(*this); + this->GetObjectList().UnlinkMultiWaitHolder(*this); } }; - using WaitableHolderOfMessageQueueForNotEmpty = WaitableHolderOfMessageQueue; - using WaitableHolderOfMessageQueueForNotFull = WaitableHolderOfMessageQueue; + using MultiWaitHolderOfMessageQueueForNotEmpty = MultiWaitHolderOfMessageQueue; + using MultiWaitHolderOfMessageQueueForNotFull = MultiWaitHolderOfMessageQueue; } diff --git a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_semaphore.hpp b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_semaphore.hpp similarity index 78% rename from libraries/libstratosphere/source/os/impl/os_waitable_holder_of_semaphore.hpp rename to libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_semaphore.hpp index bc42b4213..b3e76f639 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_semaphore.hpp +++ b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_semaphore.hpp @@ -14,12 +14,12 @@ * along with this program. If not, see . */ #pragma once -#include "os_waitable_holder_base.hpp" -#include "os_waitable_object_list.hpp" +#include "os_multiple_wait_holder_base.hpp" +#include "os_multiple_wait_object_list.hpp" namespace ams::os::impl { - class WaitableHolderOfSemaphore : public WaitableHolderOfUserObject { + class MultiWaitHolderOfSemaphore : public MultiWaitHolderOfUserObject { private: SemaphoreType *semaphore; private: @@ -27,7 +27,7 @@ namespace ams::os::impl { return this->semaphore->count > 0 ? TriBool::True : TriBool::False; } public: - explicit WaitableHolderOfSemaphore(SemaphoreType *s) : semaphore(s) { /* ... */ } + explicit MultiWaitHolderOfSemaphore(SemaphoreType *s) : semaphore(s) { /* ... */ } /* IsSignaled, Link, Unlink implemented. */ virtual TriBool IsSignaled() const override { @@ -38,14 +38,14 @@ namespace ams::os::impl { virtual TriBool LinkToObjectList() override { std::scoped_lock lk(GetReference(this->semaphore->cs_sema)); - GetReference(this->semaphore->waitlist).LinkWaitableHolder(*this); + GetReference(this->semaphore->waitlist).LinkMultiWaitHolder(*this); return this->IsSignaledImpl(); } virtual void UnlinkFromObjectList() override { std::scoped_lock lk(GetReference(this->semaphore->cs_sema)); - GetReference(this->semaphore->waitlist).UnlinkWaitableHolder(*this); + GetReference(this->semaphore->waitlist).UnlinkMultiWaitHolder(*this); } }; diff --git a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_thread.hpp b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_thread.hpp similarity index 80% rename from libraries/libstratosphere/source/os/impl/os_waitable_holder_of_thread.hpp rename to libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_thread.hpp index 19a10a89b..f47ae2608 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_thread.hpp +++ b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_thread.hpp @@ -14,11 +14,11 @@ * along with this program. If not, see . */ #pragma once -#include "os_waitable_holder_base.hpp" +#include "os_multiple_wait_holder_base.hpp" namespace ams::os::impl { - class WaitableHolderOfThread : public WaitableHolderOfUserObject { + class MultiWaitHolderOfThread : public MultiWaitHolderOfUserObject { private: ThreadType *thread; private: @@ -26,7 +26,7 @@ namespace ams::os::impl { return this->thread->state == ThreadType::State_Terminated ? TriBool::True : TriBool::False; } public: - explicit WaitableHolderOfThread(ThreadType *t) : thread(t) { /* ... */ } + explicit MultiWaitHolderOfThread(ThreadType *t) : thread(t) { /* ... */ } /* IsSignaled, Link, Unlink implemented. */ virtual TriBool IsSignaled() const override { @@ -37,14 +37,14 @@ namespace ams::os::impl { virtual TriBool LinkToObjectList() override { std::scoped_lock lk(GetReference(this->thread->cs_thread)); - GetReference(this->thread->waitlist).LinkWaitableHolder(*this); + GetReference(this->thread->waitlist).LinkMultiWaitHolder(*this); return this->IsSignaledImpl(); } virtual void UnlinkFromObjectList() override { std::scoped_lock lk(GetReference(this->thread->cs_thread)); - GetReference(this->thread->waitlist).UnlinkWaitableHolder(*this); + GetReference(this->thread->waitlist).UnlinkMultiWaitHolder(*this); } }; diff --git a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_timer_event.hpp b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_timer_event.hpp similarity index 80% rename from libraries/libstratosphere/source/os/impl/os_waitable_holder_of_timer_event.hpp rename to libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_timer_event.hpp index 949df7b7c..5558a2516 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_timer_event.hpp +++ b/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_timer_event.hpp @@ -16,22 +16,22 @@ #pragma once #include #include "os_timer_event_helper.hpp" -#include "os_waitable_holder_base.hpp" -#include "os_waitable_object_list.hpp" +#include "os_multiple_wait_holder_base.hpp" +#include "os_multiple_wait_object_list.hpp" namespace ams::os::impl { - class WaitableHolderOfTimerEvent : public WaitableHolderOfUserObject { + class MultiWaitHolderOfTimerEvent : public MultiWaitHolderOfUserObject { private: TimerEventType *event; private: TriBool IsSignaledImpl() const { - TimeSpan cur_time = this->GetManager()->GetCurrentTime(); + TimeSpan cur_time = this->GetMultiWait()->GetCurrentTime(); UpdateSignalStateAndRecalculateNextTimeToWakeupUnsafe(this->event, cur_time); return this->event->signaled ? TriBool::True : TriBool::False; } public: - explicit WaitableHolderOfTimerEvent(TimerEventType *e) : event(e) { /* ... */ } + explicit MultiWaitHolderOfTimerEvent(TimerEventType *e) : event(e) { /* ... */ } /* IsSignaled, Link, Unlink implemented. */ virtual TriBool IsSignaled() const override { @@ -42,14 +42,14 @@ namespace ams::os::impl { virtual TriBool LinkToObjectList() override { std::scoped_lock lk(GetReference(this->event->cs_timer_event)); - GetReference(this->event->waitable_object_list_storage).LinkWaitableHolder(*this); + GetReference(this->event->multi_wait_object_list_storage).LinkMultiWaitHolder(*this); return this->IsSignaledImpl(); } virtual void UnlinkFromObjectList() override { std::scoped_lock lk(GetReference(this->event->cs_timer_event)); - GetReference(this->event->waitable_object_list_storage).UnlinkWaitableHolder(*this); + GetReference(this->event->multi_wait_object_list_storage).UnlinkMultiWaitHolder(*this); } /* Gets the amount of time remaining until this wakes up. */ diff --git a/libraries/libstratosphere/source/os/impl/os_waitable_manager_impl.cpp b/libraries/libstratosphere/source/os/impl/os_multiple_wait_impl.cpp similarity index 81% rename from libraries/libstratosphere/source/os/impl/os_waitable_manager_impl.cpp rename to libraries/libstratosphere/source/os/impl/os_multiple_wait_impl.cpp index 2595b83a7..bf08db235 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_manager_impl.cpp +++ b/libraries/libstratosphere/source/os/impl/os_multiple_wait_impl.cpp @@ -14,17 +14,17 @@ * along with this program. If not, see . */ #include -#include "os_waitable_manager_impl.hpp" -#include "os_waitable_object_list.hpp" +#include "os_multiple_wait_impl.hpp" +#include "os_multiple_wait_object_list.hpp" #include "os_tick_manager.hpp" namespace ams::os::impl { - Result WaitableManagerImpl::WaitAnyImpl(WaitableHolderBase **out, bool infinite, TimeSpan timeout, bool reply, Handle reply_target) { + Result MultiWaitImpl::WaitAnyImpl(MultiWaitHolderBase **out, bool infinite, TimeSpan timeout, bool reply, Handle reply_target) { /* Prepare for processing. */ this->signaled_holder = nullptr; this->target_impl.SetCurrentThreadHandleForCancelWait(); - WaitableHolderBase *holder = this->LinkHoldersToObjectList(); + MultiWaitHolderBase *holder = this->LinkHoldersToObjectList(); /* Check if we've been signaled. */ { @@ -59,9 +59,9 @@ namespace ams::os::impl { return wait_result; } - Result WaitableManagerImpl::WaitAnyHandleImpl(WaitableHolderBase **out, bool infinite, TimeSpan timeout, bool reply, Handle reply_target) { + Result MultiWaitImpl::WaitAnyHandleImpl(MultiWaitHolderBase **out, bool infinite, TimeSpan timeout, bool reply, Handle reply_target) { Handle object_handles[MaximumHandleCount]; - WaitableHolderBase *objects[MaximumHandleCount]; + MultiWaitHolderBase *objects[MaximumHandleCount]; const s32 count = this->BuildHandleArray(object_handles, objects, MaximumHandleCount); const TimeSpan end_time = infinite ? TimeSpan::FromNanoSeconds(std::numeric_limits::max()) : GetCurrentTick().ToTimeSpan() + timeout; @@ -70,7 +70,7 @@ namespace ams::os::impl { this->current_time = GetCurrentTick().ToTimeSpan(); TimeSpan min_timeout = 0; - WaitableHolderBase *min_timeout_object = this->RecalculateNextTimeout(&min_timeout, end_time); + MultiWaitHolderBase *min_timeout_object = this->RecalculateNextTimeout(&min_timeout, end_time); s32 index = WaitInvalid; Result wait_result = ResultSuccess(); @@ -129,16 +129,17 @@ namespace ams::os::impl { *out = objects[index]; return wait_result; } + break; } reply_target = svc::InvalidHandle; } } - s32 WaitableManagerImpl::BuildHandleArray(Handle out_handles[], WaitableHolderBase *out_objects[], s32 num) { + s32 MultiWaitImpl::BuildHandleArray(Handle out_handles[], MultiWaitHolderBase *out_objects[], s32 num) { s32 count = 0; - for (WaitableHolderBase &holder_base : this->waitable_list) { + for (MultiWaitHolderBase &holder_base : this->multi_wait_list) { if (Handle handle = holder_base.GetHandle(); handle != svc::InvalidHandle) { AMS_ASSERT(count < num); @@ -151,10 +152,10 @@ namespace ams::os::impl { return count; } - WaitableHolderBase *WaitableManagerImpl::LinkHoldersToObjectList() { - WaitableHolderBase *signaled_holder = nullptr; + MultiWaitHolderBase *MultiWaitImpl::LinkHoldersToObjectList() { + MultiWaitHolderBase *signaled_holder = nullptr; - for (WaitableHolderBase &holder_base : this->waitable_list) { + for (MultiWaitHolderBase &holder_base : this->multi_wait_list) { TriBool is_signaled = holder_base.LinkToObjectList(); if (signaled_holder == nullptr && is_signaled == TriBool::True) { @@ -165,17 +166,17 @@ namespace ams::os::impl { return signaled_holder; } - void WaitableManagerImpl::UnlinkHoldersFromObjectList() { - for (WaitableHolderBase &holder_base : this->waitable_list) { + void MultiWaitImpl::UnlinkHoldersFromObjectList() { + for (MultiWaitHolderBase &holder_base : this->multi_wait_list) { holder_base.UnlinkFromObjectList(); } } - WaitableHolderBase *WaitableManagerImpl::RecalculateNextTimeout(TimeSpan *out_min_timeout, TimeSpan end_time) { - WaitableHolderBase *min_timeout_holder = nullptr; + MultiWaitHolderBase *MultiWaitImpl::RecalculateNextTimeout(TimeSpan *out_min_timeout, TimeSpan end_time) { + MultiWaitHolderBase *min_timeout_holder = nullptr; TimeSpan min_time = end_time; - for (WaitableHolderBase &holder_base : this->waitable_list) { + for (MultiWaitHolderBase &holder_base : this->multi_wait_list) { if (const TimeSpan cur_time = holder_base.GetAbsoluteWakeupTime(); cur_time < min_time) { min_timeout_holder = &holder_base; min_time = cur_time; @@ -190,7 +191,7 @@ namespace ams::os::impl { return min_timeout_holder; } - void WaitableManagerImpl::SignalAndWakeupThread(WaitableHolderBase *holder_base) { + void MultiWaitImpl::SignalAndWakeupThread(MultiWaitHolderBase *holder_base) { std::scoped_lock lk(this->cs_wait); if (this->signaled_holder == nullptr) { diff --git a/libraries/libstratosphere/source/os/impl/os_waitable_manager_impl.hpp b/libraries/libstratosphere/source/os/impl/os_multiple_wait_impl.hpp similarity index 50% rename from libraries/libstratosphere/source/os/impl/os_waitable_manager_impl.hpp rename to libraries/libstratosphere/source/os/impl/os_multiple_wait_impl.hpp index 9ac6df9c0..523032fd8 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_manager_impl.hpp +++ b/libraries/libstratosphere/source/os/impl/os_multiple_wait_impl.hpp @@ -14,41 +14,41 @@ * along with this program. If not, see . */ #pragma once -#include "os_waitable_holder_base.hpp" +#include "os_multiple_wait_holder_base.hpp" #if defined(ATMOSPHERE_OS_HORIZON) - #include "os_waitable_manager_target_impl.os.horizon.hpp" + #include "os_multiple_wait_target_impl.os.horizon.hpp" #else - #error "Unknown OS for ams::os::WaitableManagerTargetImpl" + #error "Unknown OS for ams::os::MultiWaitTargetImpl" #endif namespace ams::os::impl { - class WaitableManagerImpl { + class MultiWaitImpl { public: - static constexpr size_t MaximumHandleCount = WaitableManagerTargetImpl::MaximumHandleCount; + static constexpr size_t MaximumHandleCount = MultiWaitTargetImpl::MaximumHandleCount; static constexpr s32 WaitInvalid = -3; static constexpr s32 WaitCancelled = -2; static constexpr s32 WaitTimedOut = -1; - using ListType = util::IntrusiveListMemberTraits<&WaitableHolderBase::manager_node>::ListType; + using MultiWaitList = util::IntrusiveListMemberTraits<&MultiWaitHolderBase::multi_wait_node>::ListType; private: - ListType waitable_list; - WaitableHolderBase *signaled_holder; + MultiWaitList multi_wait_list; + MultiWaitHolderBase *signaled_holder; TimeSpan current_time; InternalCriticalSection cs_wait; - WaitableManagerTargetImpl target_impl; + MultiWaitTargetImpl target_impl; private: - Result WaitAnyImpl(WaitableHolderBase **out, bool infinite, TimeSpan timeout, bool reply, Handle reply_target); - Result WaitAnyHandleImpl(WaitableHolderBase **out, bool infinite, TimeSpan timeout, bool reply, Handle reply_target); - s32 BuildHandleArray(Handle out_handles[], WaitableHolderBase *out_objects[], s32 num); + Result WaitAnyImpl(MultiWaitHolderBase **out, bool infinite, TimeSpan timeout, bool reply, Handle reply_target); + Result WaitAnyHandleImpl(MultiWaitHolderBase **out, bool infinite, TimeSpan timeout, bool reply, Handle reply_target); + s32 BuildHandleArray(Handle out_handles[], MultiWaitHolderBase *out_objects[], s32 num); - WaitableHolderBase *LinkHoldersToObjectList(); + MultiWaitHolderBase *LinkHoldersToObjectList(); void UnlinkHoldersFromObjectList(); - WaitableHolderBase *RecalculateNextTimeout(TimeSpan *out_min_timeout, TimeSpan end_time); + MultiWaitHolderBase *RecalculateNextTimeout(TimeSpan *out_min_timeout, TimeSpan end_time); - WaitableHolderBase *WaitAnyImpl(bool infinite, TimeSpan timeout) { - WaitableHolderBase *holder = nullptr; + MultiWaitHolderBase *WaitAnyImpl(bool infinite, TimeSpan timeout) { + MultiWaitHolderBase *holder = nullptr; const Result wait_result = this->WaitAnyImpl(std::addressof(holder), infinite, timeout, false, svc::InvalidHandle); R_ASSERT(wait_result); @@ -58,48 +58,48 @@ namespace ams::os::impl { } public: /* Wait. */ - WaitableHolderBase *WaitAny() { + MultiWaitHolderBase *WaitAny() { return this->WaitAnyImpl(true, TimeSpan::FromNanoSeconds(std::numeric_limits::max())); } - WaitableHolderBase *TryWaitAny() { + MultiWaitHolderBase *TryWaitAny() { return this->WaitAnyImpl(false, TimeSpan(0)); } - WaitableHolderBase *TimedWaitAny(TimeSpan ts) { + MultiWaitHolderBase *TimedWaitAny(TimeSpan ts) { return this->WaitAnyImpl(false, ts); } - Result ReplyAndReceive(WaitableHolderBase **out, Handle reply_target) { + Result ReplyAndReceive(MultiWaitHolderBase **out, Handle reply_target) { return this->WaitAnyImpl(out, true, TimeSpan::FromNanoSeconds(std::numeric_limits::max()), true, reply_target); } /* List management. */ bool IsEmpty() const { - return this->waitable_list.empty(); + return this->multi_wait_list.empty(); } - void LinkWaitableHolder(WaitableHolderBase &holder_base) { - this->waitable_list.push_back(holder_base); + void LinkMultiWaitHolder(MultiWaitHolderBase &holder_base) { + this->multi_wait_list.push_back(holder_base); } - void UnlinkWaitableHolder(WaitableHolderBase &holder_base) { - this->waitable_list.erase(this->waitable_list.iterator_to(holder_base)); + void UnlinkMultiWaitHolder(MultiWaitHolderBase &holder_base) { + this->multi_wait_list.erase(this->multi_wait_list.iterator_to(holder_base)); } void UnlinkAll() { while (!this->IsEmpty()) { - this->waitable_list.front().SetManager(nullptr); - this->waitable_list.pop_front(); + this->multi_wait_list.front().SetMultiWait(nullptr); + this->multi_wait_list.pop_front(); } } - void MoveAllFrom(WaitableManagerImpl &other) { - /* Set manager for all of the other's waitables. */ - for (auto &w : other.waitable_list) { - w.SetManager(this); + void MoveAllFrom(MultiWaitImpl &other) { + /* Set ourselves as multi wait for all of the other's holders. */ + for (auto &w : other.multi_wait_list) { + w.SetMultiWait(this); } - this->waitable_list.splice(this->waitable_list.end(), other.waitable_list); + this->multi_wait_list.splice(this->multi_wait_list.end(), other.multi_wait_list); } /* Other. */ @@ -107,7 +107,7 @@ namespace ams::os::impl { return this->current_time; } - void SignalAndWakeupThread(WaitableHolderBase *holder_base); + void SignalAndWakeupThread(MultiWaitHolderBase *holder_base); }; } diff --git a/libraries/libstratosphere/source/os/impl/os_waitable_object_list.hpp b/libraries/libstratosphere/source/os/impl/os_multiple_wait_object_list.hpp similarity index 63% rename from libraries/libstratosphere/source/os/impl/os_waitable_object_list.hpp rename to libraries/libstratosphere/source/os/impl/os_multiple_wait_object_list.hpp index 786bc666f..842e74908 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_object_list.hpp +++ b/libraries/libstratosphere/source/os/impl/os_multiple_wait_object_list.hpp @@ -14,26 +14,26 @@ * along with this program. If not, see . */ #pragma once -#include "os_waitable_holder_base.hpp" -#include "os_waitable_manager_impl.hpp" +#include "os_multiple_wait_holder_base.hpp" +#include "os_multiple_wait_impl.hpp" namespace ams::os::impl { - class WaitableObjectList { + class MultiWaitObjectList { public: - using ListType = util::IntrusiveListMemberTraits<&WaitableHolderBase::object_list_node>::ListType; + using ListType = util::IntrusiveListMemberTraits<&MultiWaitHolderBase::object_list_node>::ListType; private: ListType object_list; public: void SignalAllThreads() { - for (WaitableHolderBase &holder_base : this->object_list) { - holder_base.GetManager()->SignalAndWakeupThread(&holder_base); + for (MultiWaitHolderBase &holder_base : this->object_list) { + holder_base.GetMultiWait()->SignalAndWakeupThread(&holder_base); } } void BroadcastAllThreads() { - for (WaitableHolderBase &holder_base : this->object_list) { - holder_base.GetManager()->SignalAndWakeupThread(nullptr); + for (MultiWaitHolderBase &holder_base : this->object_list) { + holder_base.GetMultiWait()->SignalAndWakeupThread(nullptr); } } @@ -41,11 +41,11 @@ namespace ams::os::impl { return this->object_list.empty(); } - void LinkWaitableHolder(WaitableHolderBase &holder_base) { + void LinkMultiWaitHolder(MultiWaitHolderBase &holder_base) { this->object_list.push_back(holder_base); } - void UnlinkWaitableHolder(WaitableHolderBase &holder_base) { + void UnlinkMultiWaitHolder(MultiWaitHolderBase &holder_base) { this->object_list.erase(this->object_list.iterator_to(holder_base)); } }; diff --git a/libraries/libstratosphere/source/os/impl/os_waitable_manager_target_impl.os.horizon.cpp b/libraries/libstratosphere/source/os/impl/os_multiple_wait_target_impl.os.horizon.cpp similarity index 66% rename from libraries/libstratosphere/source/os/impl/os_waitable_manager_target_impl.os.horizon.cpp rename to libraries/libstratosphere/source/os/impl/os_multiple_wait_target_impl.os.horizon.cpp index e567cf444..6573ff6e3 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_manager_target_impl.os.horizon.cpp +++ b/libraries/libstratosphere/source/os/impl/os_multiple_wait_target_impl.os.horizon.cpp @@ -14,18 +14,18 @@ * along with this program. If not, see . */ #include -#include "os_waitable_holder_base.hpp" -#include "os_waitable_manager_impl.hpp" +#include "os_multiple_wait_holder_base.hpp" +#include "os_multiple_wait_impl.hpp" namespace ams::os::impl { - Result WaitableManagerHorizonImpl::WaitSynchronizationN(s32 *out_index, s32 num, Handle arr[], s32 array_size, s64 ns) { + Result MultiWaitHorizonImpl::WaitSynchronizationN(s32 *out_index, s32 num, Handle arr[], s32 array_size, s64 ns) { AMS_ASSERT(!(num == 0 && ns == 0)); - s32 index = WaitableManagerImpl::WaitInvalid; + s32 index = MultiWaitImpl::WaitInvalid; R_TRY_CATCH(svc::WaitSynchronization(std::addressof(index), static_cast(arr), num, ns)) { - R_CATCH(svc::ResultTimedOut) { index = WaitableManagerImpl::WaitTimedOut; } - R_CATCH(svc::ResultCancelled) { index = WaitableManagerImpl::WaitCancelled; } + R_CATCH(svc::ResultTimedOut) { index = MultiWaitImpl::WaitTimedOut; } + R_CATCH(svc::ResultCancelled) { index = MultiWaitImpl::WaitCancelled; } /* All other results are critical errors. */ /* svc::ResultThreadTerminating */ /* svc::ResultInvalidHandle. */ @@ -37,17 +37,17 @@ namespace ams::os::impl { return ResultSuccess(); } - Result WaitableManagerHorizonImpl::ReplyAndReceiveN(s32 *out_index, s32 num, Handle arr[], s32 array_size, s64 ns, Handle reply_target) { + Result MultiWaitHorizonImpl::ReplyAndReceiveN(s32 *out_index, s32 num, Handle arr[], s32 array_size, s64 ns, Handle reply_target) { /* NOTE: Nintendo does not initialize this value, which seems like it can cause incorrect behavior. */ - s32 index = WaitableManagerImpl::WaitInvalid; - static_assert(WaitableManagerImpl::WaitInvalid != -1); + s32 index = MultiWaitImpl::WaitInvalid; + static_assert(MultiWaitImpl::WaitInvalid != -1); R_TRY_CATCH(svc::ReplyAndReceive(std::addressof(index), arr, num, reply_target, ns)) { - R_CATCH(svc::ResultTimedOut) { *out_index = WaitableManagerImpl::WaitTimedOut; return R_CURRENT_RESULT; } - R_CATCH(svc::ResultCancelled) { *out_index = WaitableManagerImpl::WaitCancelled; return R_CURRENT_RESULT; } + R_CATCH(svc::ResultTimedOut) { *out_index = MultiWaitImpl::WaitTimedOut; return R_CURRENT_RESULT; } + R_CATCH(svc::ResultCancelled) { *out_index = MultiWaitImpl::WaitCancelled; return R_CURRENT_RESULT; } R_CATCH(svc::ResultSessionClosed) { if (index == -1) { - *out_index = WaitableManagerImpl::WaitInvalid; + *out_index = MultiWaitImpl::WaitInvalid; return os::ResultSessionClosedForReply(); } else { *out_index = index; @@ -64,7 +64,7 @@ namespace ams::os::impl { return ResultSuccess(); } - void WaitableManagerHorizonImpl::CancelWait() { + void MultiWaitHorizonImpl::CancelWait() { R_ABORT_UNLESS(svc::CancelSynchronization(this->handle)); } diff --git a/libraries/libstratosphere/source/os/impl/os_waitable_manager_target_impl.os.horizon.hpp b/libraries/libstratosphere/source/os/impl/os_multiple_wait_target_impl.os.horizon.hpp similarity index 96% rename from libraries/libstratosphere/source/os/impl/os_waitable_manager_target_impl.os.horizon.hpp rename to libraries/libstratosphere/source/os/impl/os_multiple_wait_target_impl.os.horizon.hpp index ac7ee6b92..ad023af2a 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_manager_target_impl.os.horizon.hpp +++ b/libraries/libstratosphere/source/os/impl/os_multiple_wait_target_impl.os.horizon.hpp @@ -19,7 +19,7 @@ namespace ams::os::impl { - class WaitableManagerHorizonImpl { + class MultiWaitHorizonImpl { public: static constexpr size_t MaximumHandleCount = static_cast(ams::svc::ArgumentHandleCountMax); private: @@ -63,6 +63,6 @@ namespace ams::os::impl { } }; - using WaitableManagerTargetImpl = WaitableManagerHorizonImpl; + using MultiWaitTargetImpl = MultiWaitHorizonImpl; } diff --git a/libraries/libstratosphere/source/os/impl/os_thread_manager.cpp b/libraries/libstratosphere/source/os/impl/os_thread_manager.cpp index e6c456a75..a4e593e80 100644 --- a/libraries/libstratosphere/source/os/impl/os_thread_manager.cpp +++ b/libraries/libstratosphere/source/os/impl/os_thread_manager.cpp @@ -15,10 +15,10 @@ */ #include #include "os_thread_manager.hpp" -#include "os_waitable_manager_impl.hpp" -#include "os_waitable_holder_base.hpp" -#include "os_waitable_holder_impl.hpp" -#include "os_waitable_object_list.hpp" +#include "os_multiple_wait_impl.hpp" +#include "os_multiple_wait_holder_base.hpp" +#include "os_multiple_wait_holder_impl.hpp" +#include "os_multiple_wait_object_list.hpp" #include "os_utility.hpp" namespace ams::os::impl { diff --git a/libraries/libstratosphere/source/os/impl/os_utility.hpp b/libraries/libstratosphere/source/os/impl/os_utility.hpp index bbbd9aeeb..17c66b020 100644 --- a/libraries/libstratosphere/source/os/impl/os_utility.hpp +++ b/libraries/libstratosphere/source/os/impl/os_utility.hpp @@ -14,8 +14,6 @@ * along with this program. If not, see . */ #pragma once -#include "os_waitable_holder_base.hpp" -#include "os_waitable_manager_impl.hpp" namespace ams::os::impl { diff --git a/libraries/libstratosphere/source/os/impl/os_waitable_holder_impl.hpp b/libraries/libstratosphere/source/os/impl/os_waitable_holder_impl.hpp deleted file mode 100644 index c47983027..000000000 --- a/libraries/libstratosphere/source/os/impl/os_waitable_holder_impl.hpp +++ /dev/null @@ -1,59 +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 "os_waitable_holder_of_handle.hpp" -#include "os_waitable_holder_of_event.hpp" -#include "os_waitable_holder_of_inter_process_event.hpp" -#include "os_waitable_holder_of_interrupt_event.hpp" -#include "os_waitable_holder_of_timer_event.hpp" -#include "os_waitable_holder_of_thread.hpp" -#include "os_waitable_holder_of_semaphore.hpp" -#include "os_waitable_holder_of_message_queue.hpp" - -namespace ams::os::impl { - - struct WaitableHolderImpl { - union { - util::TypedStorage holder_of_handle_storage; - util::TypedStorage holder_of_event_storage; - util::TypedStorage holder_of_inter_process_event_storage; - util::TypedStorage holder_of_interrupt_event_storage; - util::TypedStorage holder_of_timer_event_storage; - util::TypedStorage holder_of_thread_storage; - util::TypedStorage holder_of_semaphore_storage; - util::TypedStorage holder_of_mq_for_not_full_storage; - util::TypedStorage holder_of_mq_for_not_empty_storage; - }; - }; - - #define CHECK_HOLDER(T) \ - static_assert(std::is_base_of<::ams::os::impl::WaitableHolderBase, T>::value && std::is_trivially_destructible::value, #T) - - CHECK_HOLDER(WaitableHolderOfHandle); - CHECK_HOLDER(WaitableHolderOfEvent); - CHECK_HOLDER(WaitableHolderOfInterProcessEvent); - CHECK_HOLDER(WaitableHolderOfInterruptEvent); - CHECK_HOLDER(WaitableHolderOfTimerEvent); - CHECK_HOLDER(WaitableHolderOfThread); - CHECK_HOLDER(WaitableHolderOfSemaphore); - CHECK_HOLDER(WaitableHolderOfMessageQueueForNotFull); - CHECK_HOLDER(WaitableHolderOfMessageQueueForNotEmpty); - - #undef CHECK_HOLDER - - static_assert(std::is_trivial::value && std::is_trivially_destructible::value); - static_assert(sizeof(WaitableHolderImpl) == sizeof(os::WaitableHolderType::impl_storage)); -} diff --git a/libraries/libstratosphere/source/os/os_event.cpp b/libraries/libstratosphere/source/os/os_event.cpp index 11328190a..63f78b2e5 100644 --- a/libraries/libstratosphere/source/os/os_event.cpp +++ b/libraries/libstratosphere/source/os/os_event.cpp @@ -15,8 +15,8 @@ */ #include #include "impl/os_timeout_helper.hpp" -#include "impl/os_waitable_object_list.hpp" -#include "impl/os_waitable_holder_impl.hpp" +#include "impl/os_multiple_wait_object_list.hpp" +#include "impl/os_multiple_wait_holder_impl.hpp" namespace ams::os { @@ -40,8 +40,8 @@ namespace ams::os { util::ConstructAt(event->cs_event); util::ConstructAt(event->cv_signaled); - /* Initialize the waitable object list. */ - util::ConstructAt(event->waitable_object_list_storage); + /* Initialize the multi wait object list. */ + util::ConstructAt(event->multi_wait_object_list_storage); /* Initialize member variables. */ event->signaled = signaled; @@ -61,7 +61,7 @@ namespace ams::os { event->state = EventType::State_NotInitialized; /* Destroy objects. */ - util::DestroyAt(event->waitable_object_list_storage); + util::DestroyAt(event->multi_wait_object_list_storage); util::DestroyAt(event->cv_signaled); util::DestroyAt(event->cs_event); } @@ -89,7 +89,7 @@ namespace ams::os { } /* Wake up whatever manager, if any. */ - GetReference(event->waitable_object_list_storage).SignalAllThreads(); + GetReference(event->multi_wait_object_list_storage).SignalAllThreads(); } void WaitEvent(EventType *event) { @@ -160,12 +160,12 @@ namespace ams::os { event->signaled = false; } - void InitializeWaitableHolder(WaitableHolderType *waitable_holder, EventType *event) { + void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, EventType *event) { AMS_ASSERT(event->state == EventType::State_Initialized); - util::ConstructAt(GetReference(waitable_holder->impl_storage).holder_of_event_storage, event); + util::ConstructAt(GetReference(multi_wait_holder->impl_storage).holder_of_event_storage, event); - waitable_holder->user_data = 0; + multi_wait_holder->user_data = 0; } } diff --git a/libraries/libstratosphere/source/os/os_interrupt_event.cpp b/libraries/libstratosphere/source/os/os_interrupt_event.cpp index 509ea39b8..e4732520c 100644 --- a/libraries/libstratosphere/source/os/os_interrupt_event.cpp +++ b/libraries/libstratosphere/source/os/os_interrupt_event.cpp @@ -15,8 +15,8 @@ */ #include #include "impl/os_interrupt_event_impl.hpp" -#include "impl/os_waitable_holder_impl.hpp" -#include "impl/os_waitable_object_list.hpp" +#include "impl/os_multiple_wait_holder_impl.hpp" +#include "impl/os_multiple_wait_object_list.hpp" namespace ams::os { @@ -62,12 +62,12 @@ namespace ams::os { return GetReference(event->impl).Clear(); } - void InitializeWaitableHolder(WaitableHolderType *waitable_holder, InterruptEventType *event) { + void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, InterruptEventType *event) { AMS_ASSERT(event->state == InterruptEventType::State_Initialized); - util::ConstructAt(GetReference(waitable_holder->impl_storage).holder_of_interrupt_event_storage, event); + util::ConstructAt(GetReference(multi_wait_holder->impl_storage).holder_of_interrupt_event_storage, event); - waitable_holder->user_data = 0; + multi_wait_holder->user_data = 0; } } diff --git a/libraries/libstratosphere/source/os/os_message_queue.cpp b/libraries/libstratosphere/source/os/os_message_queue.cpp index bde4dfa83..4902411de 100644 --- a/libraries/libstratosphere/source/os/os_message_queue.cpp +++ b/libraries/libstratosphere/source/os/os_message_queue.cpp @@ -15,8 +15,8 @@ */ #include #include "impl/os_timeout_helper.hpp" -#include "impl/os_waitable_object_list.hpp" -#include "impl/os_waitable_holder_impl.hpp" +#include "impl/os_multiple_wait_object_list.hpp" +#include "impl/os_multiple_wait_holder_impl.hpp" #include "impl/os_message_queue_helper.hpp" namespace ams::os { @@ -319,20 +319,20 @@ namespace ams::os { return true; } - void InitializeWaitableHolder(WaitableHolderType *waitable_holder, MessageQueueType *mq, MessageQueueWaitType type) { + void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, MessageQueueType *mq, MessageQueueWaitType type) { AMS_ASSERT(mq->state == MessageQueueType::State_Initialized); switch (type) { case MessageQueueWaitType::ForNotFull: - util::ConstructAt(GetReference(waitable_holder->impl_storage).holder_of_mq_for_not_full_storage, mq); + util::ConstructAt(GetReference(multi_wait_holder->impl_storage).holder_of_mq_for_not_full_storage, mq); break; case MessageQueueWaitType::ForNotEmpty: - util::ConstructAt(GetReference(waitable_holder->impl_storage).holder_of_mq_for_not_empty_storage, mq); + util::ConstructAt(GetReference(multi_wait_holder->impl_storage).holder_of_mq_for_not_empty_storage, mq); break; AMS_UNREACHABLE_DEFAULT_CASE(); } - waitable_holder->user_data = 0; + multi_wait_holder->user_data = 0; } } diff --git a/libraries/libstratosphere/source/os/os_multiple_wait.cpp b/libraries/libstratosphere/source/os/os_multiple_wait.cpp new file mode 100644 index 000000000..10ba242aa --- /dev/null +++ b/libraries/libstratosphere/source/os/os_multiple_wait.cpp @@ -0,0 +1,152 @@ +/* + * 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 . + */ +#include +#include "impl/os_multiple_wait_impl.hpp" +#include "impl/os_multiple_wait_holder_base.hpp" +#include "impl/os_multiple_wait_holder_impl.hpp" + +namespace ams::os { + + namespace { + + ALWAYS_INLINE impl::MultiWaitImpl &GetMultiWaitImpl(MultiWaitType *multi_wait) { + return GetReference(multi_wait->impl_storage); + } + + ALWAYS_INLINE MultiWaitHolderType *CastToMultiWaitHolder(impl::MultiWaitHolderBase *base) { + return reinterpret_cast(base); + } + + } + + void InitializeMultiWait(MultiWaitType *multi_wait) { + /* Initialize storage. */ + util::ConstructAt(multi_wait->impl_storage); + + /* Mark initialized. */ + multi_wait->state = MultiWaitType::State_Initialized; + } + + void FinalizeMultiWait(MultiWaitType *multi_wait) { + auto &impl = GetMultiWaitImpl(multi_wait); + + AMS_ASSERT(multi_wait->state == MultiWaitType::State_Initialized); + AMS_ASSERT(impl.IsEmpty()); + AMS_UNUSED(impl); + + /* Mark not initialized. */ + multi_wait->state = MultiWaitType::State_NotInitialized; + + /* Destroy. */ + util::DestroyAt(multi_wait->impl_storage); + } + + MultiWaitHolderType *WaitAny(MultiWaitType *multi_wait) { + auto &impl = GetMultiWaitImpl(multi_wait); + + AMS_ASSERT(multi_wait->state == MultiWaitType::State_Initialized); + AMS_ASSERT(!impl.IsEmpty()); + + auto *holder = CastToMultiWaitHolder(impl.WaitAny()); + AMS_ASSERT(holder != nullptr); + return holder; + } + + MultiWaitHolderType *TryWaitAny(MultiWaitType *multi_wait) { + auto &impl = GetMultiWaitImpl(multi_wait); + + AMS_ASSERT(multi_wait->state == MultiWaitType::State_Initialized); + AMS_ASSERT(!impl.IsEmpty()); + + auto *holder = CastToMultiWaitHolder(impl.TryWaitAny()); + return holder; + } + + MultiWaitHolderType *TimedWaitAny(MultiWaitType *multi_wait, TimeSpan timeout) { + auto &impl = GetMultiWaitImpl(multi_wait); + + AMS_ASSERT(multi_wait->state == MultiWaitType::State_Initialized); + AMS_ASSERT(!impl.IsEmpty()); + AMS_ASSERT(timeout.GetNanoSeconds() >= 0); + + auto *holder = CastToMultiWaitHolder(impl.TimedWaitAny(timeout)); + return holder; + } + + void FinalizeMultiWaitHolder(MultiWaitHolderType *holder) { + auto *holder_base = reinterpret_cast(GetPointer(holder->impl_storage)); + + AMS_ASSERT(!holder_base->IsLinked()); + + std::destroy_at(holder_base); + } + + void LinkMultiWaitHolder(MultiWaitType *multi_wait, MultiWaitHolderType *holder) { + auto &impl = GetMultiWaitImpl(multi_wait); + auto *holder_base = reinterpret_cast(GetPointer(holder->impl_storage)); + + AMS_ASSERT(multi_wait->state == MultiWaitType::State_Initialized); + AMS_ASSERT(!holder_base->IsLinked()); + + impl.LinkMultiWaitHolder(*holder_base); + holder_base->SetMultiWait(&impl); + } + + void UnlinkMultiWaitHolder(MultiWaitHolderType *holder) { + auto *holder_base = reinterpret_cast(GetPointer(holder->impl_storage)); + + /* Don't allow unlinking of an unlinked holder. */ + AMS_ABORT_UNLESS(holder_base->IsLinked()); + + holder_base->GetMultiWait()->UnlinkMultiWaitHolder(*holder_base); + holder_base->SetMultiWait(nullptr); + } + + void UnlinkAllMultiWaitHolder(MultiWaitType *multi_wait) { + auto &impl = GetMultiWaitImpl(multi_wait); + + AMS_ASSERT(multi_wait->state == MultiWaitType::State_Initialized); + + return impl.UnlinkAll(); + } + + void MoveAllMultiWaitHolder(MultiWaitType *_dst, MultiWaitType *_src) { + auto &dst = GetMultiWaitImpl(_dst); + auto &src = GetMultiWaitImpl(_src); + + AMS_ASSERT(_dst->state == MultiWaitType::State_Initialized); + AMS_ASSERT(_src->state == MultiWaitType::State_Initialized); + + return dst.MoveAllFrom(src); + } + + void SetMultiWaitHolderUserData(MultiWaitHolderType *holder, uintptr_t user_data) { + holder->user_data = user_data; + } + + uintptr_t GetMultiWaitHolderUserData(const MultiWaitHolderType *holder) { + return holder->user_data; + } + + void InitializeMultiWaitHolder(MultiWaitHolderType *holder, Handle handle) { + AMS_ASSERT(handle != svc::InvalidHandle); + + util::ConstructAt(GetReference(holder->impl_storage).holder_of_handle_storage, handle); + + holder->user_data = 0; + } + +} diff --git a/libraries/libstratosphere/source/os/os_sdk_reply_and_receive.cpp b/libraries/libstratosphere/source/os/os_sdk_reply_and_receive.cpp index a0242cd66..3c9016d30 100644 --- a/libraries/libstratosphere/source/os/os_sdk_reply_and_receive.cpp +++ b/libraries/libstratosphere/source/os/os_sdk_reply_and_receive.cpp @@ -14,32 +14,32 @@ * along with this program. If not, see . */ #include -#include "impl/os_waitable_manager_impl.hpp" -#include "impl/os_waitable_holder_base.hpp" -#include "impl/os_waitable_holder_impl.hpp" +#include "impl/os_multiple_wait_impl.hpp" +#include "impl/os_multiple_wait_holder_base.hpp" +#include "impl/os_multiple_wait_holder_impl.hpp" namespace ams::os { namespace { - ALWAYS_INLINE impl::WaitableManagerImpl &GetWaitableManagerImpl(WaitableManagerType *manager) { - return GetReference(manager->impl_storage); + ALWAYS_INLINE impl::MultiWaitImpl &GetMultiWaitImpl(MultiWaitType *multi_wait) { + return GetReference(multi_wait->impl_storage); } - ALWAYS_INLINE WaitableHolderType *CastToWaitableHolder(impl::WaitableHolderBase *base) { - return reinterpret_cast(base); + ALWAYS_INLINE MultiWaitHolderType *CastToMultiWaitHolder(impl::MultiWaitHolderBase *base) { + return reinterpret_cast(base); } } - Result SdkReplyAndReceive(os::WaitableHolderType **out, Handle reply_target, WaitableManagerType *manager) { - auto &impl = GetWaitableManagerImpl(manager); + Result SdkReplyAndReceive(os::MultiWaitHolderType **out, Handle reply_target, MultiWaitType *multi_wait) { + auto &impl = GetMultiWaitImpl(multi_wait); - AMS_ASSERT(manager->state == WaitableManagerType::State_Initialized); + AMS_ASSERT(multi_wait->state == MultiWaitType::State_Initialized); AMS_ASSERT(!impl.IsEmpty()); - impl::WaitableHolderBase *holder_base; - ON_SCOPE_EXIT { *out = CastToWaitableHolder(holder_base); }; + impl::MultiWaitHolderBase *holder_base; + ON_SCOPE_EXIT { *out = CastToMultiWaitHolder(holder_base); }; return impl.ReplyAndReceive(std::addressof(holder_base), reply_target); } diff --git a/libraries/libstratosphere/source/os/os_semaphore.cpp b/libraries/libstratosphere/source/os/os_semaphore.cpp index 3c99c755a..e48df5090 100644 --- a/libraries/libstratosphere/source/os/os_semaphore.cpp +++ b/libraries/libstratosphere/source/os/os_semaphore.cpp @@ -14,8 +14,8 @@ * along with this program. If not, see . */ #include -#include "impl/os_waitable_object_list.hpp" -#include "impl/os_waitable_holder_impl.hpp" +#include "impl/os_multiple_wait_object_list.hpp" +#include "impl/os_multiple_wait_holder_impl.hpp" #include "impl/os_timeout_helper.hpp" namespace ams::os { @@ -142,12 +142,12 @@ namespace ams::os { return sema->count; } - void InitializeWaitableHolder(WaitableHolderType *waitable_holder, SemaphoreType *sema) { + void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, SemaphoreType *sema) { AMS_ASSERT(sema->state == SemaphoreType::State_Initialized); - util::ConstructAt(GetReference(waitable_holder->impl_storage).holder_of_semaphore_storage, sema); + util::ConstructAt(GetReference(multi_wait_holder->impl_storage).holder_of_semaphore_storage, sema); - waitable_holder->user_data = 0; + multi_wait_holder->user_data = 0; } } diff --git a/libraries/libstratosphere/source/os/os_system_event.cpp b/libraries/libstratosphere/source/os/os_system_event.cpp index e828356e3..955f4d863 100644 --- a/libraries/libstratosphere/source/os/os_system_event.cpp +++ b/libraries/libstratosphere/source/os/os_system_event.cpp @@ -14,7 +14,7 @@ * along with this program. If not, see . */ #include -#include "impl/os_waitable_holder_impl.hpp" +#include "impl/os_multiple_wait_holder_impl.hpp" #include "impl/os_inter_process_event.hpp" #include "impl/os_timeout_helper.hpp" @@ -119,13 +119,13 @@ namespace ams::os { } } - void InitializeWaitableHolder(WaitableHolderType *waitable_holder, SystemEventType *event) { + void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, SystemEventType *event) { switch (event->state) { case SystemEventType::State_InitializedAsInterProcessEvent: - util::ConstructAt(GetReference(waitable_holder->impl_storage).holder_of_inter_process_event_storage, std::addressof(event->inter_process_event)); + util::ConstructAt(GetReference(multi_wait_holder->impl_storage).holder_of_inter_process_event_storage, std::addressof(event->inter_process_event)); break; case SystemEventType::State_InitializedAsEvent: - util::ConstructAt(GetReference(waitable_holder->impl_storage).holder_of_event_storage, std::addressof(event->event)); + util::ConstructAt(GetReference(multi_wait_holder->impl_storage).holder_of_event_storage, std::addressof(event->event)); break; AMS_UNREACHABLE_DEFAULT_CASE(); } diff --git a/libraries/libstratosphere/source/os/os_thread.cpp b/libraries/libstratosphere/source/os/os_thread.cpp index 45a8b6948..89b56a88d 100644 --- a/libraries/libstratosphere/source/os/os_thread.cpp +++ b/libraries/libstratosphere/source/os/os_thread.cpp @@ -16,7 +16,7 @@ #include #include "impl/os_thread_manager.hpp" #include "impl/os_timeout_helper.hpp" -#include "impl/os_waitable_holder_impl.hpp" +#include "impl/os_multiple_wait_holder_impl.hpp" namespace ams::os { diff --git a/libraries/libstratosphere/source/os/os_timer_event.cpp b/libraries/libstratosphere/source/os/os_timer_event.cpp index 0a632de1b..e68189ad4 100644 --- a/libraries/libstratosphere/source/os/os_timer_event.cpp +++ b/libraries/libstratosphere/source/os/os_timer_event.cpp @@ -17,8 +17,8 @@ #include "impl/os_timer_event_helper.hpp" #include "impl/os_tick_manager.hpp" #include "impl/os_timeout_helper.hpp" -#include "impl/os_waitable_object_list.hpp" -#include "impl/os_waitable_holder_impl.hpp" +#include "impl/os_multiple_wait_object_list.hpp" +#include "impl/os_multiple_wait_holder_impl.hpp" namespace ams::os { @@ -49,7 +49,7 @@ namespace ams::os { } /* Wake up whatever manager, if any. */ - GetReference(event->waitable_object_list_storage).SignalAllThreads(); + GetReference(event->multi_wait_object_list_storage).SignalAllThreads(); } } @@ -59,8 +59,8 @@ namespace ams::os { util::ConstructAt(event->cs_timer_event); util::ConstructAt(event->cv_signaled); - /* Initialize the waitable object list. */ - util::ConstructAt(event->waitable_object_list_storage); + /* Initialize the multi wait object list. */ + util::ConstructAt(event->multi_wait_object_list_storage); /* Initialize member variables. */ event->clear_mode = static_cast(clear_mode); @@ -83,7 +83,7 @@ namespace ams::os { event->state = TimerEventType::State_NotInitialized; /* Destroy objects. */ - util::DestroyAt(event->waitable_object_list_storage); + util::DestroyAt(event->multi_wait_object_list_storage); util::DestroyAt(event->cv_signaled); util::DestroyAt(event->cs_timer_event); } @@ -110,7 +110,7 @@ namespace ams::os { GetReference(event->cv_signaled).Broadcast(); /* Wake up whatever manager, if any. */ - GetReference(event->waitable_object_list_storage).SignalAllThreads(); + GetReference(event->multi_wait_object_list_storage).SignalAllThreads(); } } @@ -137,7 +137,7 @@ namespace ams::os { GetReference(event->cv_signaled).Broadcast(); /* Wake up whatever manager, if any. */ - GetReference(event->waitable_object_list_storage).SignalAllThreads(); + GetReference(event->multi_wait_object_list_storage).SignalAllThreads(); } } @@ -154,7 +154,7 @@ namespace ams::os { GetReference(event->cv_signaled).Broadcast(); /* Wake up whatever manager, if any. */ - GetReference(event->waitable_object_list_storage).SignalAllThreads(); + GetReference(event->multi_wait_object_list_storage).SignalAllThreads(); } } @@ -252,12 +252,12 @@ namespace ams::os { } } - void InitializeWaitableHolder(WaitableHolderType *waitable_holder, TimerEventType *event) { + void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, TimerEventType *event) { AMS_ASSERT(event->state == EventType::State_Initialized); - util::ConstructAt(GetReference(waitable_holder->impl_storage).holder_of_timer_event_storage, event); + util::ConstructAt(GetReference(multi_wait_holder->impl_storage).holder_of_timer_event_storage, event); - waitable_holder->user_data = 0; + multi_wait_holder->user_data = 0; } } diff --git a/libraries/libstratosphere/source/os/os_waitable.cpp b/libraries/libstratosphere/source/os/os_waitable.cpp deleted file mode 100644 index 2df27e6db..000000000 --- a/libraries/libstratosphere/source/os/os_waitable.cpp +++ /dev/null @@ -1,152 +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 . - */ -#include -#include "impl/os_waitable_manager_impl.hpp" -#include "impl/os_waitable_holder_base.hpp" -#include "impl/os_waitable_holder_impl.hpp" - -namespace ams::os { - - namespace { - - ALWAYS_INLINE impl::WaitableManagerImpl &GetWaitableManagerImpl(WaitableManagerType *manager) { - return GetReference(manager->impl_storage); - } - - ALWAYS_INLINE WaitableHolderType *CastToWaitableHolder(impl::WaitableHolderBase *base) { - return reinterpret_cast(base); - } - - } - - void InitializeWaitableManager(WaitableManagerType *manager) { - /* Initialize storage. */ - util::ConstructAt(manager->impl_storage); - - /* Mark initialized. */ - manager->state = WaitableManagerType::State_Initialized; - } - - void FinalizeWaitableManager(WaitableManagerType *manager) { - auto &impl = GetWaitableManagerImpl(manager); - - AMS_ASSERT(manager->state == WaitableManagerType::State_Initialized); - AMS_ASSERT(impl.IsEmpty()); - AMS_UNUSED(impl); - - /* Mark not initialized. */ - manager->state = WaitableManagerType::State_NotInitialized; - - /* Destroy. */ - util::DestroyAt(manager->impl_storage); - } - - WaitableHolderType *WaitAny(WaitableManagerType *manager) { - auto &impl = GetWaitableManagerImpl(manager); - - AMS_ASSERT(manager->state == WaitableManagerType::State_Initialized); - AMS_ASSERT(!impl.IsEmpty()); - - auto *holder = CastToWaitableHolder(impl.WaitAny()); - AMS_ASSERT(holder != nullptr); - return holder; - } - - WaitableHolderType *TryWaitAny(WaitableManagerType *manager) { - auto &impl = GetWaitableManagerImpl(manager); - - AMS_ASSERT(manager->state == WaitableManagerType::State_Initialized); - AMS_ASSERT(!impl.IsEmpty()); - - auto *holder = CastToWaitableHolder(impl.TryWaitAny()); - return holder; - } - - WaitableHolderType *TimedWaitAny(WaitableManagerType *manager, TimeSpan timeout) { - auto &impl = GetWaitableManagerImpl(manager); - - AMS_ASSERT(manager->state == WaitableManagerType::State_Initialized); - AMS_ASSERT(!impl.IsEmpty()); - AMS_ASSERT(timeout.GetNanoSeconds() >= 0); - - auto *holder = CastToWaitableHolder(impl.TimedWaitAny(timeout)); - return holder; - } - - void FinalizeWaitableHolder(WaitableHolderType *holder) { - auto *holder_base = reinterpret_cast(GetPointer(holder->impl_storage)); - - AMS_ASSERT(!holder_base->IsLinkedToManager()); - - std::destroy_at(holder_base); - } - - void LinkWaitableHolder(WaitableManagerType *manager, WaitableHolderType *holder) { - auto &impl = GetWaitableManagerImpl(manager); - auto *holder_base = reinterpret_cast(GetPointer(holder->impl_storage)); - - AMS_ASSERT(manager->state == WaitableManagerType::State_Initialized); - AMS_ASSERT(!holder_base->IsLinkedToManager()); - - impl.LinkWaitableHolder(*holder_base); - holder_base->SetManager(&impl); - } - - void UnlinkWaitableHolder(WaitableHolderType *holder) { - auto *holder_base = reinterpret_cast(GetPointer(holder->impl_storage)); - - /* Don't allow unlinking of an unlinked holder. */ - AMS_ABORT_UNLESS(holder_base->IsLinkedToManager()); - - holder_base->GetManager()->UnlinkWaitableHolder(*holder_base); - holder_base->SetManager(nullptr); - } - - void UnlinkAllWaitableHolder(WaitableManagerType *manager) { - auto &impl = GetWaitableManagerImpl(manager); - - AMS_ASSERT(manager->state == WaitableManagerType::State_Initialized); - - return impl.UnlinkAll(); - } - - void MoveAllWaitableHolder(WaitableManagerType *_dst, WaitableManagerType *_src) { - auto &dst = GetWaitableManagerImpl(_dst); - auto &src = GetWaitableManagerImpl(_src); - - AMS_ASSERT(_dst->state == WaitableManagerType::State_Initialized); - AMS_ASSERT(_src->state == WaitableManagerType::State_Initialized); - - return dst.MoveAllFrom(src); - } - - void SetWaitableHolderUserData(WaitableHolderType *holder, uintptr_t user_data) { - holder->user_data = user_data; - } - - uintptr_t GetWaitableHolderUserData(const WaitableHolderType *holder) { - return holder->user_data; - } - - void InitializeWaitableHolder(WaitableHolderType *holder, Handle handle) { - AMS_ASSERT(handle != svc::InvalidHandle); - - util::ConstructAt(GetReference(holder->impl_storage).holder_of_handle_storage, handle); - - holder->user_data = 0; - } - -} diff --git a/libraries/libstratosphere/source/osdbg/impl/osdbg_thread_type.os.horizon.hpp b/libraries/libstratosphere/source/osdbg/impl/osdbg_thread_type.os.horizon.hpp index f5ba193d4..6b78bd296 100644 --- a/libraries/libstratosphere/source/osdbg/impl/osdbg_thread_type.os.horizon.hpp +++ b/libraries/libstratosphere/source/osdbg/impl/osdbg_thread_type.os.horizon.hpp @@ -26,7 +26,7 @@ namespace ams::osdbg::impl { struct ThreadTypeIlp32 { AlignedStorageIlp32<0, 2, alignof(u32)> _all_threads_node; - AlignedStorageIlp32<0, 2, alignof(u32)> _waitable_object_list; + AlignedStorageIlp32<0, 2, alignof(u32)> _multi_wait_object_list; u32 _padding[4]; u8 _state; bool _stack_is_aliased; @@ -55,7 +55,7 @@ namespace ams::osdbg::impl { struct ThreadTypeIlp32Version0 { AlignedStorageIlp32<0, 2, alignof(u32)> _all_threads_node; - AlignedStorageIlp32<0, 2, alignof(u32)> _waitable_object_list; + AlignedStorageIlp32<0, 2, alignof(u32)> _multi_wait_object_list; u32 _padding[4]; u8 _state; bool _stack_is_aliased; @@ -82,7 +82,7 @@ namespace ams::osdbg::impl { struct ThreadTypeLp64 { AlignedStorageLp64<0, 2, alignof(u64)> _all_threads_node; - AlignedStorageLp64<0, 2, alignof(u64)> _waitable_object_list; + AlignedStorageLp64<0, 2, alignof(u64)> _multi_wait_object_list; u64 _padding[4]; u8 _state; bool _stack_is_aliased; @@ -110,7 +110,7 @@ namespace ams::osdbg::impl { struct ThreadTypeLp64Version0 { AlignedStorageLp64<0, 2, alignof(u64)> _all_threads_node; - AlignedStorageLp64<0, 2, alignof(u64)> _waitable_object_list; + AlignedStorageLp64<0, 2, alignof(u64)> _multi_wait_object_list; u64 _padding[4]; u8 _state; bool _stack_is_aliased; diff --git a/libraries/libstratosphere/source/sf/hipc/sf_hipc_api.cpp b/libraries/libstratosphere/source/sf/hipc/sf_hipc_api.cpp index 113c47fe0..a66c42bd9 100644 --- a/libraries/libstratosphere/source/sf/hipc/sf_hipc_api.cpp +++ b/libraries/libstratosphere/source/sf/hipc/sf_hipc_api.cpp @@ -41,12 +41,12 @@ namespace ams::sf::hipc { } - void AttachWaitableHolderForAccept(os::WaitableHolderType *holder, Handle port) { - return os::InitializeWaitableHolder(holder, port); + void AttachMultiWaitHolderForAccept(os::MultiWaitHolderType *holder, Handle port) { + return os::InitializeMultiWaitHolder(holder, port); } - void AttachWaitableHolderForReply(os::WaitableHolderType *holder, Handle request) { - return os::InitializeWaitableHolder(holder, request); + void AttachMultiWaitHolderForReply(os::MultiWaitHolderType *holder, Handle request) { + return os::InitializeMultiWaitHolder(holder, request); } Result Receive(ReceiveResult *out_recv_result, Handle session_handle, const cmif::PointerAndSize &message_buffer) { diff --git a/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp b/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp index c5b5c1ccc..87e8ca23b 100644 --- a/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp +++ b/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp @@ -32,37 +32,37 @@ namespace ams::sf::hipc { return ResultSuccess(); } - void ServerManagerBase::RegisterSessionToWaitList(ServerSession *session) { + void ServerManagerBase::RegisterServerSessionToWait(ServerSession *session) { session->has_received = false; /* Set user data tag. */ - os::SetWaitableHolderUserData(session, static_cast(UserDataTag::Session)); + os::SetMultiWaitHolderUserData(session, static_cast(UserDataTag::Session)); - this->RegisterToWaitList(session); + this->LinkToDeferredList(session); } - void ServerManagerBase::RegisterToWaitList(os::WaitableHolderType *holder) { - std::scoped_lock lk(this->waitlist_mutex); - os::LinkWaitableHolder(std::addressof(this->waitlist), holder); + void ServerManagerBase::LinkToDeferredList(os::MultiWaitHolderType *holder) { + std::scoped_lock lk(this->deferred_list_mutex); + os::LinkMultiWaitHolder(std::addressof(this->deferred_list), holder); this->notify_event.Signal(); } - void ServerManagerBase::ProcessWaitList() { - std::scoped_lock lk(this->waitlist_mutex); - os::MoveAllWaitableHolder(std::addressof(this->waitable_manager), std::addressof(this->waitlist)); + void ServerManagerBase::LinkDeferred() { + std::scoped_lock lk(this->deferred_list_mutex); + os::MoveAllMultiWaitHolder(std::addressof(this->multi_wait), std::addressof(this->deferred_list)); } - os::WaitableHolderType *ServerManagerBase::WaitSignaled() { - std::scoped_lock lk(this->waitable_selection_mutex); + os::MultiWaitHolderType *ServerManagerBase::WaitSignaled() { + std::scoped_lock lk(this->selection_mutex); while (true) { - this->ProcessWaitList(); - auto selected = os::WaitAny(std::addressof(this->waitable_manager)); + this->LinkDeferred(); + auto selected = os::WaitAny(std::addressof(this->multi_wait)); if (selected == &this->request_stop_event_holder) { return nullptr; } else if (selected == &this->notify_event_holder) { this->notify_event.Clear(); } else { - os::UnlinkWaitableHolder(selected); + os::UnlinkMultiWaitHolder(selected); return selected; } } @@ -76,19 +76,19 @@ namespace ams::sf::hipc { this->request_stop_event.Signal(); } - void ServerManagerBase::AddUserWaitableHolder(os::WaitableHolderType *waitable) { - const auto user_data_tag = static_cast(os::GetWaitableHolderUserData(waitable)); + void ServerManagerBase::AddUserMultiWaitHolder(os::MultiWaitHolderType *holder) { + const auto user_data_tag = static_cast(os::GetMultiWaitHolderUserData(holder)); AMS_ABORT_UNLESS(user_data_tag != UserDataTag::Server); AMS_ABORT_UNLESS(user_data_tag != UserDataTag::MitmServer); AMS_ABORT_UNLESS(user_data_tag != UserDataTag::Session); - this->RegisterToWaitList(waitable); + this->LinkToDeferredList(holder); } - Result ServerManagerBase::ProcessForServer(os::WaitableHolderType *holder) { - AMS_ABORT_UNLESS(static_cast(os::GetWaitableHolderUserData(holder)) == UserDataTag::Server); + Result ServerManagerBase::ProcessForServer(os::MultiWaitHolderType *holder) { + AMS_ABORT_UNLESS(static_cast(os::GetMultiWaitHolderUserData(holder)) == UserDataTag::Server); Server *server = static_cast(holder); - ON_SCOPE_EXIT { this->RegisterToWaitList(server); }; + ON_SCOPE_EXIT { this->LinkToDeferredList(server); }; /* Create new session. */ if (server->static_object) { @@ -98,18 +98,18 @@ namespace ams::sf::hipc { } } - Result ServerManagerBase::ProcessForMitmServer(os::WaitableHolderType *holder) { - AMS_ABORT_UNLESS(static_cast(os::GetWaitableHolderUserData(holder)) == UserDataTag::MitmServer); + Result ServerManagerBase::ProcessForMitmServer(os::MultiWaitHolderType *holder) { + AMS_ABORT_UNLESS(static_cast(os::GetMultiWaitHolderUserData(holder)) == UserDataTag::MitmServer); Server *server = static_cast(holder); - ON_SCOPE_EXIT { this->RegisterToWaitList(server); }; + ON_SCOPE_EXIT { this->LinkToDeferredList(server); }; /* Create resources for new session. */ return this->OnNeedsToAccept(server->index, server); } - Result ServerManagerBase::ProcessForSession(os::WaitableHolderType *holder) { - AMS_ABORT_UNLESS(static_cast(os::GetWaitableHolderUserData(holder)) == UserDataTag::Session); + Result ServerManagerBase::ProcessForSession(os::MultiWaitHolderType *holder) { + AMS_ABORT_UNLESS(static_cast(os::GetMultiWaitHolderUserData(holder)) == UserDataTag::Session); ServerSession *session = static_cast(holder); @@ -133,8 +133,8 @@ namespace ams::sf::hipc { return ResultSuccess(); } - Result ServerManagerBase::Process(os::WaitableHolderType *holder) { - switch (static_cast(os::GetWaitableHolderUserData(holder))) { + Result ServerManagerBase::Process(os::MultiWaitHolderType *holder) { + switch (static_cast(os::GetMultiWaitHolderUserData(holder))) { case UserDataTag::Server: return this->ProcessForServer(holder); case UserDataTag::MitmServer: @@ -146,12 +146,12 @@ namespace ams::sf::hipc { } bool ServerManagerBase::WaitAndProcessImpl() { - auto waitable = this->WaitSignaled(); - if (!waitable) { + if (auto *signaled_holder = this->WaitSignaled(); signaled_holder != nullptr) { + R_ABORT_UNLESS(this->Process(signaled_holder)); + return true; + } else { return false; } - R_ABORT_UNLESS(this->Process(waitable)); - return true; } void ServerManagerBase::WaitAndProcess() { diff --git a/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_session_manager.cpp b/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_session_manager.cpp index 0693625e8..983c4e089 100644 --- a/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_session_manager.cpp +++ b/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_session_manager.cpp @@ -78,7 +78,7 @@ namespace ams::sf::hipc { void ServerSessionManager::CloseSessionImpl(ServerSession *session) { const Handle session_handle = session->session_handle; - os::FinalizeWaitableHolder(session); + os::FinalizeMultiWaitHolder(session); this->DestroySession(session); R_ABORT_UNLESS(svcCloseHandle(session_handle)); } @@ -92,7 +92,7 @@ namespace ams::sf::hipc { session_memory->saved_message = this->GetSessionSavedMessageBuffer(session_memory); /* Register to wait list. */ - this->RegisterSessionToWaitList(session_memory); + this->RegisterServerSessionToWait(session_memory); return ResultSuccess(); } @@ -123,7 +123,7 @@ namespace ams::sf::hipc { session_memory->pointer_buffer = cmif::PointerAndSize(session_memory->pointer_buffer.GetAddress(), session_memory->forward_service->pointer_buffer_size); /* Register to wait list. */ - this->RegisterSessionToWaitList(session_memory); + this->RegisterServerSessionToWait(session_memory); return ResultSuccess(); } @@ -233,7 +233,7 @@ namespace ams::sf::hipc { } R_END_TRY_CATCH; /* We succeeded, so we can process future messages on this session. */ - this->RegisterSessionToWaitList(session); + this->RegisterServerSessionToWait(session); return ResultSuccess(); } } diff --git a/libraries/libvapours/source/sdmmc/impl/sdmmc_device_detector.cpp b/libraries/libvapours/source/sdmmc/impl/sdmmc_device_detector.cpp index 4deae1590..3cdf0fa61 100644 --- a/libraries/libvapours/source/sdmmc/impl/sdmmc_device_detector.cpp +++ b/libraries/libvapours/source/sdmmc/impl/sdmmc_device_detector.cpp @@ -71,18 +71,18 @@ namespace ams::sdmmc::impl { os::SystemEventType gpio_event; R_ABORT_UNLESS(gpio::BindInterrupt(std::addressof(gpio_event), std::addressof(this->gpio_pad_session))); - /* Initialize and link waitable holders. */ - os::WaitableManagerType wait_manager; - os::WaitableHolderType detector_thread_end_holder; - os::WaitableHolderType request_sleep_wake_event_holder; - os::WaitableHolderType gpio_event_holder; - os::InitializeWaitableManager(std::addressof(wait_manager)); - os::InitializeWaitableHolder(std::addressof(detector_thread_end_holder), std::addressof(this->detector_thread_end_event)); - os::LinkWaitableHolder(std::addressof(wait_manager), std::addressof(detector_thread_end_holder)); - os::InitializeWaitableHolder(std::addressof(request_sleep_wake_event_holder), std::addressof(this->request_sleep_wake_event)); - os::LinkWaitableHolder(std::addressof(wait_manager), std::addressof(request_sleep_wake_event_holder)); - os::InitializeWaitableHolder(std::addressof(gpio_event_holder), std::addressof(gpio_event)); - os::LinkWaitableHolder(std::addressof(wait_manager), std::addressof(gpio_event_holder)); + /* Initialize and link multi wait/holders. */ + os::MultiWaitType multi_wait; + os::MultiWaitHolderType detector_thread_end_holder; + os::MultiWaitHolderType request_sleep_wake_event_holder; + os::MultiWaitHolderType gpio_event_holder; + os::InitializeMultiWait(std::addressof(multi_wait)); + os::InitializeMultiWaitHolder(std::addressof(detector_thread_end_holder), std::addressof(this->detector_thread_end_event)); + os::LinkMultiWaitHolder(std::addressof(multi_wait), std::addressof(detector_thread_end_holder)); + os::InitializeMultiWaitHolder(std::addressof(request_sleep_wake_event_holder), std::addressof(this->request_sleep_wake_event)); + os::LinkMultiWaitHolder(std::addressof(multi_wait), std::addressof(request_sleep_wake_event_holder)); + os::InitializeMultiWaitHolder(std::addressof(gpio_event_holder), std::addressof(gpio_event)); + os::LinkMultiWaitHolder(std::addressof(multi_wait), std::addressof(gpio_event_holder)); /* Wait before detecting the initial state of the card. */ os::SleepThread(TimeSpan::FromMilliSeconds(this->gpio_debounce_ms)); @@ -99,7 +99,7 @@ namespace ams::sdmmc::impl { /* Wait, servicing our events. */ while (true) { /* Get the signaled holder. */ - os::WaitableHolderType *signaled_holder = os::WaitAny(std::addressof(wait_manager)); + os::MultiWaitHolderType *signaled_holder = os::WaitAny(std::addressof(multi_wait)); /* Process the holder. */ bool insert_change = false; @@ -115,13 +115,13 @@ namespace ams::sdmmc::impl { os::SignalEvent(std::addressof(this->acknowledge_sleep_awake_event)); /* Temporarily unlink our interrupt event. */ - os::UnlinkWaitableHolder(std::addressof(gpio_event_holder)); + os::UnlinkMultiWaitHolder(std::addressof(gpio_event_holder)); /* Wait to be signaled. */ - signaled_holder = os::WaitAny(std::addressof(wait_manager)); + signaled_holder = os::WaitAny(std::addressof(multi_wait)); /* Link our interrupt event back in. */ - os::LinkWaitableHolder(std::addressof(wait_manager), std::addressof(gpio_event_holder)); + os::LinkMultiWaitHolder(std::addressof(multi_wait), std::addressof(gpio_event_holder)); /* We're awake again. Either because we should exit, or because we were asked to wake up. */ os::ClearEvent(std::addressof(this->request_sleep_wake_event)); @@ -170,14 +170,14 @@ namespace ams::sdmmc::impl { /* Disable interrupts to our gpio event. */ gpio::SetInterruptEnable(std::addressof(this->gpio_pad_session), false); - /* Finalize and unlink waitable holders. */ - os::UnlinkWaitableHolder(std::addressof(gpio_event_holder)); - os::FinalizeWaitableHolder(std::addressof(gpio_event_holder)); - os::UnlinkWaitableHolder(std::addressof(request_sleep_wake_event_holder)); - os::FinalizeWaitableHolder(std::addressof(request_sleep_wake_event_holder)); - os::UnlinkWaitableHolder(std::addressof(detector_thread_end_holder)); - os::FinalizeWaitableHolder(std::addressof(detector_thread_end_holder)); - os::FinalizeWaitableManager(std::addressof(wait_manager)); + /* Finalize and unlink multi wait/holders. */ + os::UnlinkMultiWaitHolder(std::addressof(gpio_event_holder)); + os::FinalizeMultiWaitHolder(std::addressof(gpio_event_holder)); + os::UnlinkMultiWaitHolder(std::addressof(request_sleep_wake_event_holder)); + os::FinalizeMultiWaitHolder(std::addressof(request_sleep_wake_event_holder)); + os::UnlinkMultiWaitHolder(std::addressof(detector_thread_end_holder)); + os::FinalizeMultiWaitHolder(std::addressof(detector_thread_end_holder)); + os::FinalizeMultiWait(std::addressof(multi_wait)); /* Finalize the gpio session. */ gpio::UnbindInterrupt(std::addressof(this->gpio_pad_session)); diff --git a/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_host_standard_controller.cpp b/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_host_standard_controller.cpp index f03d15399..fd6ec1030 100644 --- a/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_host_standard_controller.cpp +++ b/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_host_standard_controller.cpp @@ -173,7 +173,7 @@ namespace ams::sdmmc::impl { this->EnsureControl(); /* Wait for the interrupt to be signaled. */ - os::WaitableHolderType *signaled_holder = os::TimedWaitAny(std::addressof(this->waitable_manager), TimeSpan::FromMilliSeconds(timeout_ms)); + os::MultiWaitHolderType *signaled_holder = os::TimedWaitAny(std::addressof(this->multi_wait), TimeSpan::FromMilliSeconds(timeout_ms)); if (signaled_holder == std::addressof(this->interrupt_event_holder)) { /* We received the interrupt. */ return ResultSuccess(); @@ -781,15 +781,15 @@ namespace ams::sdmmc::impl { void SdHostStandardController::Initialize() { #if defined(AMS_SDMMC_USE_OS_EVENTS) { - os::InitializeWaitableManager(std::addressof(this->waitable_manager)); + os::InitializeMultiWait(std::addressof(this->multi_wait)); AMS_ABORT_UNLESS(this->interrupt_event != nullptr); - os::InitializeWaitableHolder(std::addressof(this->interrupt_event_holder), this->interrupt_event); - os::LinkWaitableHolder(std::addressof(this->waitable_manager), std::addressof(this->interrupt_event_holder)); + os::InitializeMultiWaitHolder(std::addressof(this->interrupt_event_holder), this->interrupt_event); + os::LinkMultiWaitHolder(std::addressof(this->multi_wait), std::addressof(this->interrupt_event_holder)); if (this->removed_event != nullptr) { - os::InitializeWaitableHolder(std::addressof(this->removed_event_holder), this->removed_event); - os::LinkWaitableHolder(std::addressof(this->waitable_manager), std::addressof(this->removed_event_holder)); + os::InitializeMultiWaitHolder(std::addressof(this->removed_event_holder), this->removed_event); + os::LinkMultiWaitHolder(std::addressof(this->multi_wait), std::addressof(this->removed_event_holder)); } } #endif @@ -799,14 +799,14 @@ namespace ams::sdmmc::impl { #if defined(AMS_SDMMC_USE_OS_EVENTS) { if (this->removed_event != nullptr) { - os::UnlinkWaitableHolder(std::addressof(this->removed_event_holder)); - os::FinalizeWaitableHolder(std::addressof(this->removed_event_holder)); + os::UnlinkMultiWaitHolder(std::addressof(this->removed_event_holder)); + os::FinalizeMultiWaitHolder(std::addressof(this->removed_event_holder)); } - os::UnlinkWaitableHolder(std::addressof(this->interrupt_event_holder)); - os::FinalizeWaitableHolder(std::addressof(this->interrupt_event_holder)); + os::UnlinkMultiWaitHolder(std::addressof(this->interrupt_event_holder)); + os::FinalizeMultiWaitHolder(std::addressof(this->interrupt_event_holder)); - os::FinalizeWaitableManager(std::addressof(this->waitable_manager)); + os::FinalizeMultiWait(std::addressof(this->multi_wait)); } #endif } diff --git a/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_host_standard_controller.hpp b/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_host_standard_controller.hpp index 7bdf0a3cd..b432357a6 100644 --- a/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_host_standard_controller.hpp +++ b/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_host_standard_controller.hpp @@ -39,11 +39,11 @@ namespace ams::sdmmc::impl { #endif #if defined(AMS_SDMMC_USE_OS_EVENTS) - os::WaitableManagerType waitable_manager; + os::MultiWaitType multi_wait; os::InterruptEventType *interrupt_event; - os::WaitableHolderType interrupt_event_holder; + os::MultiWaitHolderType interrupt_event_holder; os::EventType *removed_event; - os::WaitableHolderType removed_event_holder; + os::MultiWaitHolderType removed_event_holder; #endif u64 next_sdma_address; diff --git a/stratosphere/fatal/source/fatal_config.cpp b/stratosphere/fatal/source/fatal_config.cpp index 3a04b92de..5ce0e53db 100644 --- a/stratosphere/fatal/source/fatal_config.cpp +++ b/stratosphere/fatal/source/fatal_config.cpp @@ -32,19 +32,19 @@ namespace ams::fatal::srv { /* Global event. */ os::SystemEventType g_fatal_dirty_event; - os::WaitableHolderType g_fatal_dirty_waitable_holder; + os::MultiWaitHolderType g_fatal_dirty_multi_wait_holder; bool g_initialized; } - os::WaitableHolderType *GetFatalDirtyWaitableHolder() { + os::MultiWaitHolderType *GetFatalDirtyMultiWaitHolder() { if (AMS_UNLIKELY(!g_initialized)) { os::AttachReadableHandleToSystemEvent(std::addressof(g_fatal_dirty_event), GetFatalDirtyEventReadableHandle(), true, os::EventClearMode_ManualClear); - os::InitializeWaitableHolder(std::addressof(g_fatal_dirty_waitable_holder), std::addressof(g_fatal_dirty_event)); - os::SetWaitableHolderUserData(std::addressof(g_fatal_dirty_waitable_holder), reinterpret_cast(std::addressof(g_fatal_dirty_waitable_holder))); + os::InitializeMultiWaitHolder(std::addressof(g_fatal_dirty_multi_wait_holder), std::addressof(g_fatal_dirty_event)); + os::SetMultiWaitHolderUserData(std::addressof(g_fatal_dirty_multi_wait_holder), reinterpret_cast(std::addressof(g_fatal_dirty_multi_wait_holder))); g_initialized = true; } - return std::addressof(g_fatal_dirty_waitable_holder); + return std::addressof(g_fatal_dirty_multi_wait_holder); } void OnFatalDirtyEvent() { diff --git a/stratosphere/fatal/source/fatal_config.hpp b/stratosphere/fatal/source/fatal_config.hpp index 2e0941c68..1244a5fd3 100644 --- a/stratosphere/fatal/source/fatal_config.hpp +++ b/stratosphere/fatal/source/fatal_config.hpp @@ -88,7 +88,7 @@ namespace ams::fatal::srv { } }; - os::WaitableHolderType *GetFatalDirtyWaitableHolder(); + os::MultiWaitHolderType *GetFatalDirtyMultiWaitHolder(); void OnFatalDirtyEvent(); const FatalConfig &GetFatalConfig(); diff --git a/stratosphere/fatal/source/fatal_main.cpp b/stratosphere/fatal/source/fatal_main.cpp index 5e10fb08f..b2531b40b 100644 --- a/stratosphere/fatal/source/fatal_main.cpp +++ b/stratosphere/fatal/source/fatal_main.cpp @@ -218,8 +218,8 @@ int main(int argc, char **argv) R_ABORT_UNLESS(g_server_manager.RegisterObjectForServer(g_private_service_object.GetShared(), PrivateServiceName, PrivateMaxSessions)); /* Add dirty event holder. */ - auto *dirty_event_holder = ams::fatal::srv::GetFatalDirtyWaitableHolder(); - g_server_manager.AddUserWaitableHolder(dirty_event_holder); + auto *dirty_event_holder = ams::fatal::srv::GetFatalDirtyMultiWaitHolder(); + g_server_manager.AddUserMultiWaitHolder(dirty_event_holder); /* Loop forever, servicing our services. */ /* Because fatal has a user wait holder, we need to specify how to process manually. */ @@ -227,7 +227,7 @@ int main(int argc, char **argv) if (signaled_holder == dirty_event_holder) { /* Dirty event holder was signaled. */ fatal::srv::OnFatalDirtyEvent(); - g_server_manager.AddUserWaitableHolder(signaled_holder); + g_server_manager.AddUserMultiWaitHolder(signaled_holder); } else { /* A server/session was signaled. Have the manager handle it. */ R_ABORT_UNLESS(g_server_manager.Process(signaled_holder)); diff --git a/stratosphere/pm/source/impl/pm_process_info.cpp b/stratosphere/pm/source/impl/pm_process_info.cpp index a8252eab5..bdf641804 100644 --- a/stratosphere/pm/source/impl/pm_process_info.cpp +++ b/stratosphere/pm/source/impl/pm_process_info.cpp @@ -19,8 +19,8 @@ namespace ams::pm::impl { ProcessInfo::ProcessInfo(Handle h, os::ProcessId pid, ldr::PinId pin, const ncm::ProgramLocation &l, const cfg::OverrideStatus &s) : process_id(pid), pin_id(pin), loc(l), status(s), handle(h), state(svc::ProcessState_Created), flags(0) { - os::InitializeWaitableHolder(std::addressof(this->waitable_holder), this->handle); - os::SetWaitableHolderUserData(std::addressof(this->waitable_holder), reinterpret_cast(this)); + os::InitializeMultiWaitHolder(std::addressof(this->multi_wait_holder), this->handle); + os::SetMultiWaitHolderUserData(std::addressof(this->multi_wait_holder), reinterpret_cast(this)); } ProcessInfo::~ProcessInfo() { @@ -38,8 +38,8 @@ namespace ams::pm::impl { svcCloseHandle(this->handle); this->handle = INVALID_HANDLE; - /* Unlink the process from its waitable manager. */ - os::UnlinkWaitableHolder(std::addressof(this->waitable_holder)); + /* Unlink the process from its multi wait. */ + os::UnlinkMultiWaitHolder(std::addressof(this->multi_wait_holder)); } } diff --git a/stratosphere/pm/source/impl/pm_process_info.hpp b/stratosphere/pm/source/impl/pm_process_info.hpp index 5c3d53618..1315f4c31 100644 --- a/stratosphere/pm/source/impl/pm_process_info.hpp +++ b/stratosphere/pm/source/impl/pm_process_info.hpp @@ -46,7 +46,7 @@ namespace ams::pm::impl { Handle handle; svc::ProcessState state; u32 flags; - os::WaitableHolderType waitable_holder; + os::MultiWaitHolderType multi_wait_holder; private: void SetFlag(Flag flag) { this->flags |= flag; @@ -64,8 +64,8 @@ namespace ams::pm::impl { ~ProcessInfo(); void Cleanup(); - void LinkToWaitableManager(os::WaitableManagerType &manager) { - os::LinkWaitableHolder(std::addressof(manager), std::addressof(this->waitable_holder)); + void LinkToMultiWait(os::MultiWaitType &multi_wait) { + os::LinkMultiWaitHolder(std::addressof(multi_wait), std::addressof(this->multi_wait_holder)); } Handle GetHandle() const { diff --git a/stratosphere/pm/source/impl/pm_process_manager.cpp b/stratosphere/pm/source/impl/pm_process_manager.cpp index 5b0a05a16..49256d046 100644 --- a/stratosphere/pm/source/impl/pm_process_manager.cpp +++ b/stratosphere/pm/source/impl/pm_process_manager.cpp @@ -150,33 +150,33 @@ namespace ams::pm::impl { constinit std::atomic g_application_hook; /* Forward declarations. */ - Result LaunchProcess(os::WaitableManagerType &waitable_manager, const LaunchProcessArgs &args); + Result LaunchProcess(os::MultiWaitType &multi_wait, const LaunchProcessArgs &args); void OnProcessSignaled(ProcessListAccessor &list, ProcessInfo *process_info); /* Helpers. */ void ProcessTrackingMain(void *arg) { /* This is the main loop of the process tracking thread. */ - /* Setup waitable manager. */ - os::WaitableManagerType process_waitable_manager; - os::WaitableHolderType start_event_holder; - os::InitializeWaitableManager(std::addressof(process_waitable_manager)); - os::InitializeWaitableHolder(std::addressof(start_event_holder), g_process_launch_start_event.GetBase()); - os::LinkWaitableHolder(std::addressof(process_waitable_manager), std::addressof(start_event_holder)); + /* Setup multi wait/holders. */ + os::MultiWaitType process_multi_wait; + os::MultiWaitHolderType start_event_holder; + os::InitializeMultiWait(std::addressof(process_multi_wait)); + os::InitializeMultiWaitHolder(std::addressof(start_event_holder), g_process_launch_start_event.GetBase()); + os::LinkMultiWaitHolder(std::addressof(process_multi_wait), std::addressof(start_event_holder)); while (true) { - auto signaled_holder = os::WaitAny(std::addressof(process_waitable_manager)); + auto signaled_holder = os::WaitAny(std::addressof(process_multi_wait)); if (signaled_holder == &start_event_holder) { /* Launch start event signaled. */ /* TryWait will clear signaled, preventing duplicate notifications. */ if (g_process_launch_start_event.TryWait()) { - g_process_launch_result = LaunchProcess(process_waitable_manager, g_process_launch_args); + g_process_launch_result = LaunchProcess(process_multi_wait, g_process_launch_args); g_process_launch_finish_event.Signal(); } } else { /* Some process was signaled. */ ProcessListAccessor list(g_process_list); - OnProcessSignaled(list, reinterpret_cast(os::GetWaitableHolderUserData(signaled_holder))); + OnProcessSignaled(list, reinterpret_cast(os::GetMultiWaitHolderUserData(signaled_holder))); } } } @@ -220,7 +220,7 @@ namespace ams::pm::impl { g_process_info_allocator.FreeProcessInfo(process_info); } - Result LaunchProcess(os::WaitableManagerType &waitable_manager, const LaunchProcessArgs &args) { + Result LaunchProcess(os::MultiWaitType &multi_wait, const LaunchProcessArgs &args) { /* Get Program Info. */ ldr::ProgramInfo program_info; cfg::OverrideStatus override_status; @@ -260,7 +260,7 @@ namespace ams::pm::impl { { ProcessListAccessor list(g_process_list); list->push_back(*process_info); - process_info->LinkToWaitableManager(waitable_manager); + process_info->LinkToMultiWait(multi_wait); } /* Prevent resource leakage if register fails. */ @@ -362,7 +362,7 @@ namespace ams::pm::impl { process_info->ClearUnhandledException(); break; case svc::ProcessState_Terminated: - /* Free process resources, unlink from waitable manager. */ + /* Free process resources, unlink from multi wait. */ process_info->Cleanup(); if (hos::GetVersion() < hos::Version_5_0_0 && process_info->ShouldSignalOnExit()) { diff --git a/stratosphere/sm/source/sm_tipc_server.cpp b/stratosphere/sm/source/sm_tipc_server.cpp index 9dc4dc897..447eb8513 100644 --- a/stratosphere/sm/source/sm_tipc_server.cpp +++ b/stratosphere/sm/source/sm_tipc_server.cpp @@ -47,7 +47,7 @@ namespace ams::sm { private: struct Entry { sm::ServiceName service_name{sm::InvalidServiceName}; - tipc::WaitableObject object{}; + tipc::ObjectHolder object{}; u8 message_buffer[svc::ipc::MessageBufferSize]; }; private: @@ -83,7 +83,7 @@ namespace ams::sm { return tipc::ResultRequestDeferred(); } - void ProcessRegisterRetry(tipc::WaitableObject &object) { + void ProcessRegisterRetry(tipc::ObjectHolder &object) { /* Verify that we have a processing entry. */ AMS_ABORT_UNLESS(m_processing_entry != nullptr);