| 1 | #include "basis/seadRawPrint.h" |
| 2 | #include "thread/seadEvent.h" |
| 3 | |
| 4 | namespace sead |
| 5 | { |
| 6 | Event::Event() : IDisposer() {} |
| 7 | |
| 8 | Event::Event(bool manual_reset) : Event() |
| 9 | { |
| 10 | initialize(manual_reset); |
| 11 | } |
| 12 | |
| 13 | Event::Event(Heap* disposer_heap) : Event(disposer_heap, HeapNullOption::UseSpecifiedOrContainHeap) |
| 14 | { |
| 15 | } |
| 16 | |
| 17 | Event::Event(Heap* disposer_heap, bool manual_reset) : Event(disposer_heap) |
| 18 | { |
| 19 | initialize(manual_reset); |
| 20 | } |
| 21 | |
| 22 | Event::Event(Heap* disposer_heap, IDisposer::HeapNullOption heap_null_option) |
| 23 | : IDisposer(disposer_heap, heap_null_option) |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | Event::Event(Heap* disposer_heap, IDisposer::HeapNullOption heap_null_option, bool manual_reset) |
| 28 | : Event(disposer_heap, heap_null_option) |
| 29 | { |
| 30 | initialize(manual_reset); |
| 31 | } |
| 32 | |
| 33 | Event::~Event() |
| 34 | { |
| 35 | setInitialized(false); |
| 36 | nn::os::FinalizeLightEvent(&mEventInner); |
| 37 | } |
| 38 | |
| 39 | void Event::initialize(bool manual_reset) |
| 40 | { |
| 41 | #ifdef SEAD_DEBUG |
| 42 | SEAD_ASSERT_MSG(!mInitialized, "Event is already initialized." ); |
| 43 | #endif |
| 44 | nn::os::InitializeLightEvent(&mEventInner, initiallySignaled: false, |
| 45 | eventClearMode: manual_reset ? nn::os::EventClearMode_ManualClear : |
| 46 | nn::os::EventClearMode_AutoClear); |
| 47 | setInitialized(true); |
| 48 | } |
| 49 | |
| 50 | void Event::wait() |
| 51 | { |
| 52 | #ifdef SEAD_DEBUG |
| 53 | SEAD_ASSERT_MSG(mInitialized, "Event is not initialized." ); |
| 54 | #endif |
| 55 | nn::os::WaitLightEvent(&mEventInner); |
| 56 | } |
| 57 | |
| 58 | bool Event::wait(TickSpan duration) |
| 59 | { |
| 60 | #ifdef SEAD_DEBUG |
| 61 | SEAD_ASSERT_MSG(mInitialized, "Event is not initialized." ); |
| 62 | #endif |
| 63 | return nn::os::TimedWaitLightEvent(&mEventInner, nn::os::ConvertToTimeSpan(ticks: duration.toTicks())); |
| 64 | } |
| 65 | |
| 66 | void Event::setSignal() |
| 67 | { |
| 68 | #ifdef SEAD_DEBUG |
| 69 | SEAD_ASSERT_MSG(mInitialized, "Event is not initialized." ); |
| 70 | #endif |
| 71 | nn::os::SignalLightEvent(&mEventInner); |
| 72 | } |
| 73 | |
| 74 | void Event::resetSignal() |
| 75 | { |
| 76 | #ifdef SEAD_DEBUG |
| 77 | SEAD_ASSERT_MSG(mInitialized, "Event is not initialized." ); |
| 78 | #endif |
| 79 | nn::os::ClearLightEvent(&mEventInner); |
| 80 | } |
| 81 | } // namespace sead |
| 82 | |