Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 1 addition & 27 deletions include/nn/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
#include <nn/types.h>

#include <nn/os/detail/os_InternalCriticalSection.h>
#include <nn/os/os_Event.h>
#include <nn/os/os_MessageQueueTypes.h>
#include <nn/os/os_Mutex.h>
#include <nn/os/os_MutexTypes.h>
#include <nn/os/os_ThreadTypes.h>

namespace nn {
namespace os {

namespace detail {

class MultiWaitObjectList;
struct InterProcessEventType {
enum State {
State_NotInitialized = 0,
Expand Down Expand Up @@ -49,22 +48,6 @@ struct LightEventType {
std::aligned_storage_t<0xc, 4> storage;
};

struct EventType {
util::TypedStorage<detail::MultiWaitObjectList, 16, 8> _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<EventType>::value, "EventType non trivial");
typedef EventType Event;

enum EventClearMode { EventClearMode_ManualClear, EventClearMode_AutoClear };

struct ConditionVariableType {};

struct SemaphoreType {
Expand Down Expand Up @@ -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*);
Expand Down
47 changes: 47 additions & 0 deletions include/nn/os/os_Event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include <nn/os/os_EventCommon.h>
#include <nn/os/os_EventTypes.h>
#include <nn/time.h>
#include <nn/util.h>

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
5 changes: 5 additions & 0 deletions include/nn/os/os_EventCommon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

namespace nn::os {
enum EventClearMode { EventClearMode_ManualClear, EventClearMode_AutoClear };
} // namespace nn::os
26 changes: 26 additions & 0 deletions include/nn/os/os_EventTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <nn/os/detail/os_InternalConditionVariable.h>
#include <nn/os/detail/os_InternalCriticalSection.h>
#include <nn/util/util_TypedStorage.h>

namespace nn::os {

namespace detail {
class MultiWaitObjectList;
} // namespace detail

struct EventType {
util::TypedStorage<detail::MultiWaitObjectList, 16, 8> _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<EventType>::value, "EventType non trivial");

} // namespace nn::os
Loading