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