CTR Pia  4.11.3
Game Communication Engine
common_ScopedLock.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: common_ScopedLock.h
4 
5  Copyright Nintendo. 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 
14 
15 #pragma once
16 
17 #include <pia/common/common_definitions.h>
18 
19 
20 namespace nn
21 {
22 namespace pia
23 {
24 namespace common
25 {
26 
27 /*!
28 @cond PRIVATE
29 @brief Locks while this instance is in existence.
30 */
31 template <typename T>
32 class ScopedLock : public common::RootObject
33 {
34 public:
35  explicit ScopedLock(T* pTarget)
36  : m_pTarget(pTarget)
37  {
38  m_pTarget->Lock();
39  }
40 
41  ~ScopedLock()
42  {
43  m_pTarget->Unlock();
44  }
45 
46 private:
47  T* m_pTarget;
48 };
49 //! @endcond
50 }
51 }
52 } // end of namespace nn::pia::common
Definition: assert.h:115