1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: os_WaitableCounter.h 4 5 Copyright (C)2009 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: 32759 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NN_OS_OS_WAITABLETIMER_H_ 17 #define NN_OS_OS_WAITABLETIMER_H_ 18 19 #ifdef __cplusplus 20 21 #include <nn/fnd/fnd_Interlocked.h> 22 #include <nn/util/util_NonCopyable.h> 23 #include <nn/Handle.h> 24 #include <nn/Result.h> 25 #include <nn/svc.h> 26 27 namespace nn { namespace os { 28 29 class WaitableCounter 30 { 31 private: 32 static nnHandle s_Handle; 33 34 private: 35 typedef nn::fnd::InterlockedVariable<s32> ValueType; 36 ValueType m_Value; 37 38 public: 39 static void Initialize(); 40 41 static void Finalize(); 42 43 ValueType& operator *() { return m_Value; } 44 const ValueType& operator *() const { return m_Value; } 45 ValueType* operator->() { return &m_Value; } 46 DecrementAndWaitIfLessThan(s32 value)47 Result DecrementAndWaitIfLessThan(s32 value) 48 { 49 return ArbitrateAddress(nn::os::ARBITRATION_TYPE_DECREMENT_AND_WAIT_IF_LESS_THAN, value); 50 } 51 WaitIfLessThan(s32 value)52 Result WaitIfLessThan(s32 value) 53 { 54 return ArbitrateAddress(nn::os::ARBITRATION_TYPE_WAIT_IF_LESS_THAN, value); 55 } 56 Signal(s32 num)57 Result Signal(s32 num) 58 { 59 return ArbitrateAddress(nn::os::ARBITRATION_TYPE_SIGNAL, num); 60 } 61 SignalAll()62 Result SignalAll() 63 { 64 return Signal(-1); 65 } 66 67 private: ArbitrateAddress(nn::os::ArbitrationType type,s32 value)68 Result ArbitrateAddress(nn::os::ArbitrationType type, s32 value) 69 { 70 return nn::svc::ArbitrateAddress(s_Handle, reinterpret_cast<uptr>(&m_Value), type, value); 71 } 72 }; 73 74 75 }} // namespace nn::os 76 77 #endif // __cplusplus 78 79 #endif 80