Changeset 36521 in vbox for trunk/include/iprt/cpp
- Timestamp:
- Apr 4, 2011 12:24:23 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/lock.h
r36508 r36521 1 1 /** @file 2 * IPRT - RTLockClasses for Scope-based Locking.2 * IPRT - Classes for Scope-based Locking. 3 3 */ 4 4 … … 39 39 */ 40 40 41 class RT Lock;41 class RTCLock; 42 42 43 43 /** … … 48 48 * a global variable, for class wide purposes. 49 49 * 50 * This is best used together with RT Lock.50 * This is best used together with RTCLock. 51 51 */ 52 class RT LockMtx52 class RTCLockMtx 53 53 { 54 friend class RT Lock;54 friend class RTCLock; 55 55 56 56 private: … … 58 58 59 59 public: 60 RT LockMtx()60 RTCLockMtx() 61 61 { 62 62 #ifdef RT_LOCK_STRICT_ORDER … … 70 70 71 71 /** Use to when creating locks that belongs in the same "class". */ 72 RT LockMtx(RT_SRC_POS_DECL, uint32_t uSubClass = RTLOCKVAL_SUB_CLASS_NONE)72 RTCLockMtx(RT_SRC_POS_DECL, uint32_t uSubClass = RTLOCKVAL_SUB_CLASS_NONE) 73 73 { 74 74 #ifdef RT_LOCK_STRICT_ORDER … … 83 83 } 84 84 85 ~RT LockMtx()85 ~RTCLockMtx() 86 86 { 87 87 RTCritSectDelete(&mMtx); 88 88 } 89 89 90 // lock() and unlock() are private so that only 91 // friend RTLock can access them 90 /* lock() and unlock() are private so that only friend RTCLock can access 91 them. */ 92 92 private: 93 93 inline void lock() … … 106 106 * The stack object for automatic locking and unlocking. 107 107 * 108 * This is a helper class for automatic locks, to simplify 109 * requesting a RTLockMtx and to not forget releasing it. 110 * To request a RTLockMtx, simply create an instance of RTLock 111 * on the stack and pass the mutex to it: 108 * This is a helper class for automatic locks, to simplify requesting a 109 * RTCLockMtx and to not forget releasing it. To request a RTCLockMtx, simply 110 * create an instance of RTCLock on the stack and pass the mutex to it: 112 111 * 113 112 * @code 114 extern RT LockMtx gMtx; // wherever this is113 extern RTCLockMtx gMtx; // wherever this is 115 114 ... 116 115 if (...) 117 116 { 118 RT Lock lock(gMtx);117 RTCLock lock(gMtx); 119 118 ... // do stuff 120 119 // when lock goes out of scope, destructor releases the mutex … … 122 121 @endcode 123 122 * 124 * You can also explicitly release the mutex by calling RT Lock::release().123 * You can also explicitly release the mutex by calling RTCLock::release(). 125 124 * This might be helpful if the lock doesn't go out of scope early enough 126 125 * for your mutex to be released. 127 126 */ 128 class RT Lock127 class RTCLock 129 128 { 130 129 private: 131 RT LockMtx &mMtx;130 RTCLockMtx &m_rMtx; 132 131 bool mfLocked; 133 132 134 133 public: 135 RT Lock(RTLockMtx &aMtx)136 : m Mtx(aMtx)134 RTCLock(RTCLockMtx &a_rMtx) 135 : m_rMtx(a_rMtx) 137 136 { 138 m Mtx.lock();137 m_rMtx.lock(); 139 138 mfLocked = true; 140 139 } 141 140 142 ~RT Lock()141 ~RTCLock() 143 142 { 144 143 if (mfLocked) 145 m Mtx.unlock();144 m_rMtx.unlock(); 146 145 } 147 146 … … 150 149 if (mfLocked) 151 150 { 152 m Mtx.unlock();151 m_rMtx.unlock(); 153 152 mfLocked = false; 154 153 }
Note:
See TracChangeset
for help on using the changeset viewer.