1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     ut_Lock.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:$
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NW_UT_LOCK_H_
17 #define NW_UT_LOCK_H_
18 
19 #ifdef NW_PLATFORM_CTR
20 #include <nn/os/os_Mutex.h>
21 #else
22 #include <nn/os/ipc/os_Mutex.h>
23 #endif
24 
25 #include <nw/types.h>
26 #include <nw/config.h>
27 #include <nw/ut/ut_Inlines.h>
28 #include <nw/os/os_Mutex.h>
29 #include <nw/ut/ut_Preprocessor.h>
30 
31 namespace nw {
32 namespace ut {
33 
34 namespace internal {
35 
36 template<typename Type>
37 class AutoLock
38 {
39 private:
40     NW_DISALLOW_COPY_AND_ASSIGN(AutoLock);
41 
42 public:
43     // コンストラクタでロックを行う
AutoLock(Type & lockObj)44     AutoLock(Type& lockObj) : m_LockObj(lockObj)
45     {
46         m_LockObj.Lock();
47     }
48 
49     // デストラクタでアンロックを行う
~AutoLock()50     ~AutoLock()
51     {
52         m_LockObj.Unlock();
53     }
54 
55 private:
56     Type& m_LockObj;
57 };
58 
59 } /* namespace internal */
60 
61 typedef internal::AutoLock<nw::os::LockObject>   AutoMutexLock;
62 
63 } /* namespace ut */
64 } /* namespace nw */
65 
66 #endif //  NW_UT_LOCK_H_
67