24 Super(
"Deadlock Detector"),
43 static_cast<void *
>(tcs.first),
87 if (itr->first == &a_CS)
131 WorldAges::iterator itr =
m_WorldAges.find(a_WorldName);
140 if (WorldAge.
m_Age == a_Age)
150 WorldAge.
m_Age = a_Age;
161 LOGERROR(
"Deadlock detected: world %s has been stuck at age %lld. Aborting the server.",
162 a_WorldName.c_str(),
static_cast<long long>(a_WorldAge.count())
165 ASSERT(!
"Deadlock detected");
178 LOG(
"CS at %p, %s: RecursionCount = %d, ThreadIDHash = %04llx",
179 static_cast<void *
>(cs.first), cs.second.c_str(),
180 cs.first->m_RecursionCount,
static_cast<UInt64>(std::hash<std::thread::id>()(cs.first->m_OwningThreadID))
const int CYCLE_MILLISECONDS
Number of milliseconds per cycle.
std::chrono::duration< signed long long int, cTickTime::period > cTickTimeLong
unsigned long long UInt64
void LOGERROR(std::string_view a_Format, const Args &... args)
void LOGWARNING(std::string_view a_Format, const Args &... args)
void LOG(std::string_view a_Format, const Args &... args)
void UntrackCriticalSection(cCriticalSection &a_CS)
Removes the CS from the tracking.
void CheckWorldAge(const AString &a_WorldName, cTickTimeLong a_Age)
Checks if the world's age has changed, updates the world's stats; calls DeadlockDetected() if deadloc...
int m_IntervalSec
Number of secods for which the ages must be the same for the detection to trigger.
void ListTrackedCSs()
Outputs a listing of the tracked CSs, together with their name and state.
virtual ~cDeadlockDetect() override
cCriticalSection m_CS
Protects m_TrackedCriticalSections from multithreaded access.
void SetWorldAge(const AString &a_WorldName, cTickTimeLong a_Age)
Sets the initial world age.
void DeadlockDetected(const AString &a_WorldName, cTickTimeLong a_WorldAge)
Called when a deadlock is detected in a world.
void TrackCriticalSection(cCriticalSection &a_CS, const AString &a_Name)
Adds the critical section for tracking.
std::vector< std::pair< cCriticalSection *, AString > > m_TrackedCriticalSections
CriticalSections that are tracked (their status output on deadlock).
virtual void Execute(void) override
This function, overloaded by the descendants, is called in the new thread.
cTickTimeLong m_Age
Last m_WorldAge that has been detected in this world.
int m_NumCyclesSame
Number of cycles for which the age has been the same.
RAII for cCriticalSection - locks the CS on creation, unlocks on destruction.
std::atomic< bool > m_ShouldTerminate
The overriden Execute() method should check this value periodically and terminate if this is true.
void Start(void)
Starts the thread; returns without waiting for the actual start.
bool ForEachWorld(cWorldListCallback a_Callback)
Calls the callback for each world; returns true if the callback didn't abort (return true)
virtual cTickTimeLong GetWorldAge(void) const override
const AString & GetName(void) const
Returns the name of the world.