diff options
Diffstat (limited to 'src/OSSupport/CriticalSection.h')
-rw-r--r-- | src/OSSupport/CriticalSection.h | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/src/OSSupport/CriticalSection.h b/src/OSSupport/CriticalSection.h index 275d1a7e8..7634e5a8c 100644 --- a/src/OSSupport/CriticalSection.h +++ b/src/OSSupport/CriticalSection.h @@ -7,9 +7,10 @@ class cCriticalSection { - friend class cDeadlockDetect; // Allow the DeadlockDetect to read the internals, so that it may output some statistics + friend class cDeadlockDetect; // Allow the DeadlockDetect to read the internals, so that it may output some + // statistics -public: + public: void Lock(void); void Unlock(void); @@ -17,29 +18,28 @@ public: /** Returns true if the CS is currently locked. Note that since it relies on the m_RecursionCount value, it is inherently thread-unsafe, prone to false positives. - Also, due to multithreading, the state can change between this when function is evaluated and the returned value is used. - To be used in ASSERT(IsLocked()) only. */ + Also, due to multithreading, the state can change between this when function is evaluated and the returned value is + used. To be used in ASSERT(IsLocked()) only. */ bool IsLocked(void); /** Returns true if the CS is currently locked by the thread calling this function. Note that since it relies on the m_RecursionCount value, it is inherently thread-unsafe, prone to false positives. - Also, due to multithreading, the state can change between this when function is evaluated and the returned value is used. - To be used in ASSERT(IsLockedByCurrentThread()) only. */ + Also, due to multithreading, the state can change between this when function is evaluated and the returned value is + used. To be used in ASSERT(IsLockedByCurrentThread()) only. */ bool IsLockedByCurrentThread(void); -private: - + private: /** Number of times that this CS is currently locked (levels of recursion). Zero if not locked. - Note that this value should be considered true only when the CS is locked; without the lock, it is UndefinedBehavior to even read it, - but making it std::atomic would impose too much of a runtime penalty. - It is only ever read without the lock in the DeadlockDetect, where the server is terminating anyway. */ + Note that this value should be considered true only when the CS is locked; without the lock, it is UndefinedBehavior + to even read it, but making it std::atomic would impose too much of a runtime penalty. It is only ever read without + the lock in the DeadlockDetect, where the server is terminating anyway. */ int m_RecursionCount; /** ID of the thread that is currently holding the CS. - Note that this value should be considered true only when the CS is locked; without the lock, it is UndefinedBehavior to even read it, - but making it std::atomic would impose too much of a runtime penalty. - When unlocked, the value stored here has no meaning, it may be an ID of a previous holder, or it could be any garbage. - It is only ever read without the lock in the DeadlockDetect, where the server is terminating anyway. */ + Note that this value should be considered true only when the CS is locked; without the lock, it is UndefinedBehavior + to even read it, but making it std::atomic would impose too much of a runtime penalty. When unlocked, the value + stored here has no meaning, it may be an ID of a previous holder, or it could be any garbage. It is only ever read + without the lock in the DeadlockDetect, where the server is terminating anyway. */ std::thread::id m_OwningThreadID; std::recursive_mutex m_Mutex; @@ -53,12 +53,12 @@ class cCSLock { cCriticalSection * m_CS; - // Unlike a cCriticalSection, this object should be used from a single thread, therefore access to m_IsLocked is not threadsafe - // In Windows, it is an error to call cCriticalSection::Unlock() multiple times if the lock is not held, + // Unlike a cCriticalSection, this object should be used from a single thread, therefore access to m_IsLocked is not + // threadsafe In Windows, it is an error to call cCriticalSection::Unlock() multiple times if the lock is not held, // therefore we need to check this value whether we are locked or not. bool m_IsLocked; -public: + public: cCSLock(cCriticalSection * a_CS); cCSLock(cCriticalSection & a_CS); ~cCSLock(); @@ -67,9 +67,9 @@ public: void Lock(void); void Unlock(void); -private: + private: DISALLOW_COPY_AND_ASSIGN(cCSLock); -} ; +}; @@ -79,14 +79,11 @@ private: class cCSUnlock { cCSLock & m_Lock; -public: + + public: cCSUnlock(cCSLock & a_Lock); ~cCSUnlock(); -private: + private: DISALLOW_COPY_AND_ASSIGN(cCSUnlock); -} ; - - - - +}; |