1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: os_MutexCTR.h 4 5 Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. 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 $Revision: 25116 $ 14 *---------------------------------------------------------------------------*/ 15 16 #include <nn/os/os_Mutex.h> 17 #include <nw/types.h> 18 19 namespace nw { 20 namespace os { 21 namespace internal { 22 23 //--------------------------------------------------------------------------- 24 //! @brief CTR 用の Mutex の具象クラスです。 25 //--------------------------------------------------------------------------- 26 class LockObject 27 { 28 public: LockObject()29 /* ctor */ LockObject() 30 { 31 m_CriticalSection.Initialize(); 32 } 33 ~LockObject()34 /* dtor */ ~LockObject() 35 { 36 m_CriticalSection.Finalize(); 37 } 38 Lock()39 void Lock() 40 { 41 m_CriticalSection.Enter(); 42 } 43 TryLock()44 bool TryLock() 45 { 46 return m_CriticalSection.TryEnter(); 47 } 48 Unlock()49 void Unlock() 50 { 51 m_CriticalSection.Leave(); 52 } 53 54 private: 55 nn::os::CriticalSection m_CriticalSection; 56 }; 57 58 59 60 //--------------------------------------------------------------------------- 61 //! @brief CTR 用の Interrupts の具象クラスです。 62 //! このクラスは実際には何も処理をおこないません。 63 //--------------------------------------------------------------------------- 64 class Interrupts 65 { 66 public: Disable()67 static bool Disable() 68 { 69 bool previous = m_Enabled; 70 m_Enabled = false; 71 return previous; 72 } 73 Enable()74 static bool Enable() 75 { 76 bool previous = m_Enabled; 77 m_Enabled = true; 78 return previous; 79 } 80 Restore(bool level)81 static bool Restore(bool level) 82 { 83 bool previous = m_Enabled; 84 m_Enabled = level; 85 return previous; 86 } 87 88 private: 89 static bool m_Enabled; 90 }; 91 92 93 } // namespace internal 94 } // namespace os 95 } // namespace nw 96