1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: os_MutexCTRWIN.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/ipc/os_Mutex.h> 19 #include <nn/os/interrupt.h> 20 21 #include <nw/types.h> 22 23 namespace nw { 24 namespace os { 25 namespace internal { 26 27 //--------------------------------------------------------------------------- 28 //! @brief CTRWIN 用の Mutex の具象クラスです。 29 //--------------------------------------------------------------------------- 30 class LockObject 31 { 32 public: LockObject()33 /* ctor */ LockObject() 34 { 35 nn::os::ipc::InitMutex( &m_Mutex ); 36 } 37 ~LockObject()38 /* dtor */ virtual ~LockObject() 39 { 40 nn::os::ipc::DestroyMutex( m_Mutex ); 41 } 42 Lock()43 virtual void Lock() 44 { 45 nn::os::ipc::LockMutex( m_Mutex ); 46 } 47 TryLock()48 virtual bool TryLock() 49 { 50 nn::Result result = nn::os::ipc::TryLockMutex( m_Mutex ); 51 return result.IsSuccess(); 52 } 53 Unlock()54 virtual void Unlock() 55 { 56 nn::os::ipc::UnlockMutex( m_Mutex ); 57 } 58 59 private: 60 nn::os::ipc::Mutex m_Mutex; 61 }; 62 63 64 class Interrupts 65 { 66 public: Disable()67 static bool Disable() 68 { 69 return (OS_DisableInterrupts() != FALSE); 70 } 71 Enable()72 static bool Enable() 73 { 74 return (OS_EnableInterrupts() != FALSE); 75 } 76 Restore(bool level)77 static bool Restore(bool level) 78 { 79 return (OS_RestoreInterrupts( level? TRUE : FALSE ) != FALSE); 80 } 81 }; 82 83 84 } // namespace internal 85 } // namespace os 86 } // namespace nw 87