From 16e83c2e08b64bab3e27e8f1869b8a3570f924b0 Mon Sep 17 00:00:00 2001 From: Nitr4m12 <67806925+Nitr4m12@users.noreply.github.com> Date: Wed, 2 Sep 2026 15:20:23 -0400 Subject: [PATCH] os: Implement `os::Event` --- CMakeLists.txt | 3 +++ include/nn/os.h | 28 +------------------- include/nn/os/os_Event.h | 47 ++++++++++++++++++++++++++++++++++ include/nn/os/os_EventCommon.h | 5 ++++ include/nn/os/os_EventTypes.h | 26 +++++++++++++++++++ 5 files changed, 82 insertions(+), 27 deletions(-) create mode 100644 include/nn/os/os_Event.h create mode 100644 include/nn/os/os_EventCommon.h create mode 100644 include/nn/os/os_EventTypes.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 77d547e4..0bf7d378 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,6 +171,9 @@ add_library(NintendoSDK OBJECT include/nn/oe.h include/nn/util.h include/nn/image.h + include/nn/os/os_Event.h + include/nn/os/os_EventCommon.h + include/nn/os/os_EventTypes.h include/nn/util/AccessorBase.h include/nn/util/MathTypes.h include/nn/util/util_Arithmetic.h diff --git a/include/nn/os.h b/include/nn/os.h index 6f27d49f..843d4f7a 100644 --- a/include/nn/os.h +++ b/include/nn/os.h @@ -11,9 +11,9 @@ #include #include +#include #include #include -#include #include namespace nn { @@ -21,7 +21,6 @@ namespace os { namespace detail { -class MultiWaitObjectList; struct InterProcessEventType { enum State { State_NotInitialized = 0, @@ -49,22 +48,6 @@ struct LightEventType { std::aligned_storage_t<0xc, 4> storage; }; -struct EventType { - util::TypedStorage _multiWaitObjectList; - bool _signalState; - bool _initiallySignaled; - uint8_t _clearMode; - uint8_t _state; - uint32_t _broadcastCounterLower; - uint32_t _broadcastCounterUpper; - detail::InternalCriticalSectionStorage _csEvent; - detail::InternalConditionVariableStorage _cvSignaled; -}; -static_assert(std::is_trivial::value, "EventType non trivial"); -typedef EventType Event; - -enum EventClearMode { EventClearMode_ManualClear, EventClearMode_AutoClear }; - struct ConditionVariableType {}; struct SemaphoreType { @@ -154,15 +137,6 @@ void SleepThread(nn::TimeSpan); void WaitThread(nn::os::ThreadType*); void SetThreadCoreMask(nn::os::ThreadType*, int, u64 mask); -// EVENTS -void InitializeEvent(EventType*, bool initiallySignaled, EventClearMode eventClearMode); -void FinalizeEvent(EventType*); -void SignalEvent(EventType*); -void WaitEvent(EventType*); -bool TryWaitEvent(EventType*); -bool TimedWaitEvent(EventType*, nn::TimeSpan); -void ClearEvent(EventType*); - // LIGHT EVENTS void InitializeLightEvent(LightEventType*, bool initiallySignaled, EventClearMode eventClearMode); void FinalizeLightEvent(LightEventType*); diff --git a/include/nn/os/os_Event.h b/include/nn/os/os_Event.h new file mode 100644 index 00000000..6692dc8d --- /dev/null +++ b/include/nn/os/os_Event.h @@ -0,0 +1,47 @@ +#pragma once + +#include +#include +#include +#include + +namespace nn::os { + +void InitializeEvent(EventType*, bool initiallySignaled, EventClearMode eventClearMode); +void FinalizeEvent(EventType*); +void SignalEvent(EventType*); +void WaitEvent(EventType*); +bool TryWaitEvent(EventType*); +bool TimedWaitEvent(EventType*, nn::TimeSpan); +void ClearEvent(EventType*); + +class Event { + NN_NO_COPY(Event); + NN_NO_MOVE(Event); + +public: + explicit Event(EventClearMode clearMode) { InitializeEvent(&m_Event, false, clearMode); } + + ~Event() { FinalizeEvent(&m_Event); } + + void Wait() { WaitEvent(&m_Event); } + + bool TryWait() { return TryWaitEvent(&m_Event); } + + bool TimedWait(TimeSpan timeSpan) { return TimedWaitEvent(&m_Event, timeSpan); } + + void Signal() { SignalEvent(&m_Event); } + + void Clear() { ClearEvent(&m_Event); } + + operator EventType&() { return m_Event; } + + operator const EventType&() const { return m_Event; } + + EventType* GetBase() { return &m_Event; } + +private: + EventType m_Event; +}; + +} // namespace nn::os diff --git a/include/nn/os/os_EventCommon.h b/include/nn/os/os_EventCommon.h new file mode 100644 index 00000000..62da5114 --- /dev/null +++ b/include/nn/os/os_EventCommon.h @@ -0,0 +1,5 @@ +#pragma once + +namespace nn::os { +enum EventClearMode { EventClearMode_ManualClear, EventClearMode_AutoClear }; +} // namespace nn::os diff --git a/include/nn/os/os_EventTypes.h b/include/nn/os/os_EventTypes.h new file mode 100644 index 00000000..695248dd --- /dev/null +++ b/include/nn/os/os_EventTypes.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include + +namespace nn::os { + +namespace detail { +class MultiWaitObjectList; +} // namespace detail + +struct EventType { + util::TypedStorage _multiWaitObjectList; + bool _signalState; + bool _initiallySignaled; + uint8_t _clearMode; + uint8_t _state; + uint32_t _broadcastCounterLower; + uint32_t _broadcastCounterUpper; + detail::InternalCriticalSectionStorage _csEvent; + detail::InternalConditionVariableStorage _cvSignaled; +}; +static_assert(std::is_trivial::value, "EventType non trivial"); + +} // namespace nn::os