Cuberite
A lightweight, fast and extensible game server for Minecraft
|
#include <CriticalSection.h>
Public Member Functions | |
cCriticalSection (void) | |
bool | IsLocked (void) |
Returns true if the CS is currently locked. More... | |
bool | IsLockedByCurrentThread (void) |
Returns true if the CS is currently locked by the thread calling this function. More... | |
void | Lock (void) |
void | Unlock (void) |
Private Attributes | |
std::recursive_mutex | m_Mutex |
std::thread::id | m_OwningThreadID |
ID of the thread that is currently holding the CS. More... | |
int | m_RecursionCount |
Number of times that this CS is currently locked (levels of recursion). More... | |
Friends | |
class | cDeadlockDetect |
Definition at line 8 of file CriticalSection.h.
cCriticalSection::cCriticalSection | ( | void | ) |
Definition at line 12 of file CriticalSection.cpp.
bool cCriticalSection::IsLocked | ( | void | ) |
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.
Definition at line 45 of file CriticalSection.cpp.
bool cCriticalSection::IsLockedByCurrentThread | ( | 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.
Definition at line 54 of file CriticalSection.cpp.
void cCriticalSection::Lock | ( | void | ) |
Definition at line 21 of file CriticalSection.cpp.
void cCriticalSection::Unlock | ( | void | ) |
Definition at line 33 of file CriticalSection.cpp.
|
friend |
Definition at line 10 of file CriticalSection.h.
|
private |
Definition at line 45 of file CriticalSection.h.
|
private |
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.
Definition at line 43 of file CriticalSection.h.
|
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.
Definition at line 36 of file CriticalSection.h.