1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: os_MutexCTR.h 4 5 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain proprietary 8 information of Nintendo and/or its licensed developers and are protected by 9 national and international copyright laws. They may not be disclosed to third 10 parties or copied or duplicated in any form, in whole or in part, without the 11 prior written consent of Nintendo. 12 13 The content herein is highly confidential and should be handled accordingly. 14 15 $Revision: 31311 $ 16 *---------------------------------------------------------------------------*/ 17 18 #include <nn/os/os_Mutex.h> 19 #include <nw/types.h> 20 21 namespace nw { 22 namespace os { 23 namespace internal { 24 25 //--------------------------------------------------------------------------- 26 //! @brief CTR 用の Mutex の具象クラスです。 27 //--------------------------------------------------------------------------- 28 class LockObject 29 { 30 public: LockObject()31 /* ctor */ LockObject() 32 { 33 m_CriticalSection.Initialize(); 34 } 35 ~LockObject()36 /* dtor */ ~LockObject() 37 { 38 m_CriticalSection.Finalize(); 39 } 40 Lock()41 void Lock() 42 { 43 m_CriticalSection.Enter(); 44 } 45 TryLock()46 bool TryLock() 47 { 48 return m_CriticalSection.TryEnter(); 49 } 50 Unlock()51 void Unlock() 52 { 53 m_CriticalSection.Leave(); 54 } 55 56 private: 57 nn::os::CriticalSection m_CriticalSection; 58 }; 59 60 61 62 //--------------------------------------------------------------------------- 63 //! @brief CTR 用の Interrupts の具象クラスです。 64 //! このクラスは実際には何も処理をおこないません。 65 //--------------------------------------------------------------------------- 66 class Interrupts 67 { 68 public: Disable()69 static bool Disable() 70 { 71 bool previous = m_Enabled; 72 m_Enabled = false; 73 return previous; 74 } 75 Enable()76 static bool Enable() 77 { 78 bool previous = m_Enabled; 79 m_Enabled = true; 80 return previous; 81 } 82 Restore(bool level)83 static bool Restore(bool level) 84 { 85 bool previous = m_Enabled; 86 m_Enabled = level; 87 return previous; 88 } 89 90 private: 91 static bool m_Enabled; 92 }; 93 94 95 } // namespace internal 96 } // namespace os 97 } // namespace nw 98