1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: os_Event.cpp
4
5 Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Rev: 46347 $
14 *---------------------------------------------------------------------------*/
15
16 #include <nn/os/os_Event.h>
17 #include <nn/assert.h>
18 #include <nn/config.h>
19 #include <nn/os/os_Result.h>
20 #include <nn/os/os_Synchronization.h>
21 #include <nn/svc/svc_Stub.h>
22
23 #include "os_Limits.h"
24
25 //---------------------------------------------------------------------------
26
27 using namespace nn;
28 using namespace nn::svc;
29
30 #include <new>
31
32 using namespace nn::os;
33 using namespace nn::fnd;
34
35 namespace nn { namespace os {
36
37 #if NN_PLATFORM_HAS_MMU
GetCurrentCount()38 s32 Event::GetCurrentCount()
39 {
40 return os::detail::GetLimitCurrentCount(LIMITABLE_RESOURCE_MAX_EVENT);
41 }
42
GetMaxCount()43 s32 Event::GetMaxCount()
44 {
45 return os::detail::GetLimitMaxCount(LIMITABLE_RESOURCE_MAX_EVENT);
46 }
47 #endif // if NN_PLATFORM_HAS_MMU
48
49 }}
50
51 extern "C" {
52
NN_UTIL_DETAIL_CLIBIMPL_DEFINE_CONVERSION(nnosEventToWaitObject,nnosEvent,nnosWaitObject,Event,WaitObject)53 NN_UTIL_DETAIL_CLIBIMPL_DEFINE_CONVERSION(nnosEventToWaitObject, nnosEvent, nnosWaitObject, Event, WaitObject)
54 NN_UTIL_DETAIL_CLIBIMPL_DEFINE_CONVERSION(nnosWaitObjectToEvent, nnosWaitObject, nnosEvent, WaitObject, Event)
55
56 void nnosEventInitialize(nnosEvent* p, bool isManualReset)
57 {
58 new (p) Event(isManualReset);
59 }
60
nnosEventTryInitialize(nnosEvent * p,bool manualReset)61 bool nnosEventTryInitialize(nnosEvent* p, bool manualReset)
62 {
63 new (p) Event();
64 Event* pEvent = reinterpret_cast<Event*>(p);
65 Result result = pEvent->TryInitialize(manualReset);
66 return result.IsSuccess();
67 }
68
nnosEventSignal(nnosEvent * p)69 void nnosEventSignal(nnosEvent* p)
70 {
71 Event* pEvent = reinterpret_cast<Event*>(p);
72 pEvent->Signal();
73 }
74
nnosEventWaitSignal(nnosEvent * p)75 void nnosEventWaitSignal(nnosEvent* p)
76 {
77 Event* pEvent = reinterpret_cast<Event*>(p);
78 pEvent->Wait();
79 }
80
nnosEventTryWaitSignal(nnosEvent * p,s64 nanoSecondsTimeout)81 bool nnosEventTryWaitSignal(nnosEvent* p, s64 nanoSecondsTimeout)
82 {
83 Event* pEvent = reinterpret_cast<Event*>(p);
84 return pEvent->Wait(TimeSpan::FromNanoSeconds(nanoSecondsTimeout));
85 }
86
nnosEventClearSignal(nnosEvent * p)87 void nnosEventClearSignal(nnosEvent* p)
88 {
89 Event* pEvent = reinterpret_cast<Event*>(p);
90 pEvent->ClearSignal();
91 }
92
nnosEventFinalize(nnosEvent * p)93 void nnosEventFinalize(nnosEvent* p)
94 {
95 Event* pEvent = reinterpret_cast<Event*>(p);
96 pEvent->~Event();
97 }
98
99 }
100