CTR-Pia  5.4.3
Game Communication Engine
 全て クラス ネームスペース 関数 変数 型定義 列挙型 列挙型の値 ページ
common_CriticalSection.h
1 /*--------------------------------------------------------------------------------*
2  Copyright (C)Nintendo All rights reserved.
3 
4  These coded instructions, statements, and computer programs contain proprietary
5  information of Nintendo and/or its licensed developers and are protected by
6  national and international copyright laws. They may not be disclosed to third
7  parties or copied or duplicated in any form, in whole or in part, without the
8  prior written consent of Nintendo.
9 
10  The content herein is highly confidential and should be handled accordingly.
11  *--------------------------------------------------------------------------------*/
12 
13 
14 #pragma once
15 
16 #include <nn/pia/pia_Definitions.h>
17 #include <nn/pia/common/common_RootObject.h>
18 
19 #if NN_PIA_CAFE
20 #include <sdk_ver.h>
21 
22 #if CAFE_OS_SDK_VERSION >= 21002
23 #define NN_PIA_ENABLE_FAST_MUTEX 1
24 #else
25 #define NN_PIA_ENABLE_FAST_MUTEX 0
26 #endif
27 
28 #elif NN_PIA_A || NN_PIA_B
29 #include <pthread.h>
30 #endif
31 
32 #define PIA_CRITICAL_SECTION_LOCK_CHECKER_ENABLE NN_PIA_UNDER_DEVELOP
33 
34 
35 namespace nn
36 {
37 namespace pia
38 {
39 namespace common
40 {
41 
42 /*!
43 @cond PRIVATE
44  @brief CriticalSection のラッパーです。
45  */
46 class CriticalSection : public common::RootObject
47 {
48 public:
49  /*!
50  @brief コンストラクタです。
51  @param[in] lockOrder ロック順の値です。CriticalSectionLockChecker::LockOrder の値を指定する必要があります。
52  */
53  explicit CriticalSection(int lockOrder = -1);
54 
55 
56  /*!
57  @brief destructorです。
58  */
59  ~CriticalSection();
60 
61 
62  /*!
63  @brief ロックします。
64  */
65  void Lock();
66 
67 
68  /*!
69  @brief ロックを試みます。
70  @return ロックに成功すると true を返します。
71  */
72  bool TryLock();
73 
74 
75  /*!
76  @brief ロックを開放します。
77  */
78  void Unlock();
79 
80 
81  /*!
82  @brief デバッグに有用な情報をプリントします。
83 
84  @param[in] flag トレースフラグの論理和。詳細は@ref TraceFlag 型を参照してください。
85  */
86  void Trace(uint64_t flag) const;
87 
88 
89 /*!
90  @brief ロック順取得
91  */
92 #if PIA_CRITICAL_SECTION_LOCK_CHECKER_ENABLE
93  int GetLockOrder() const
94  {
95  return m_LockOrder;
96  }
97 #endif
98 
99 
100 private:
101 #if NN_PIA_NINTENDOSDK
102  nn::os::MutexType m_MutexInner;
103 #elif NN_PIA_CTR
104  nn::os::CriticalSection m_CriticalSection;
105 #elif NN_PIA_WIN
106  CRITICAL_SECTION m_CriticalSection;
107 #elif NN_PIA_CAFE
108 #if NN_PIA_ENABLE_FAST_MUTEX
109  OSFastMutex m_FastMutex;
110 #else
111  OSMutex m_Mutex;
112 #endif
113 #elif NN_PIA_A || NN_PIA_B
114  void initialize_pthread(pthread_mutex_t* p_pthread);
115  pthread_mutex_t mMutexInner;
116 #else
117 #error "invalid platform"
118 #endif
119 
120 #if PIA_CRITICAL_SECTION_LOCK_CHECKER_ENABLE
121  int m_LockOrder;
122 #endif
123 };
124 //! @endcond
125 }
126 }
127 } // end of namespace nn::pia::common