Cuberite
A lightweight, fast and extensible game server for Minecraft
Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Types | List of all members
cDeadlockDetect Class Reference

#include <DeadlockDetect.h>

Inheritance diagram for cDeadlockDetect:
Inheritance graph
[legend]
Collaboration diagram for cDeadlockDetect:
Collaboration graph
[legend]

Classes

struct  sWorldAge
 

Public Member Functions

 cDeadlockDetect ()
 
void Start (int a_IntervalSec)
 Starts the detection. More...
 
void TrackCriticalSection (cCriticalSection &a_CS, const AString &a_Name)
 Adds the critical section for tracking. More...
 
void UntrackCriticalSection (cCriticalSection &a_CS)
 Removes the CS from the tracking. More...
 
virtual ~cDeadlockDetect () override
 
- Public Member Functions inherited from cIsThread
 cIsThread (AString &&a_ThreadName)
 
bool IsCurrentThread (void) const
 Returns true if the thread calling this function is the thread contained within this object. More...
 
void Start (void)
 Starts the thread; returns without waiting for the actual start. More...
 
void Stop (void)
 Signals the thread to terminate and waits until it's finished. More...
 
virtual ~cIsThread ()
 

Protected Types

typedef std::map< AString, sWorldAgeWorldAges
 Maps world name -> sWorldAge. More...
 

Protected Member Functions

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 deadlock detected. More...
 
void DeadlockDetected (const AString &a_WorldName, cTickTimeLong a_WorldAge)
 Called when a deadlock is detected in a world. More...
 
virtual void Execute (void) override
 This function, overloaded by the descendants, is called in the new thread. More...
 
void ListTrackedCSs ()
 Outputs a listing of the tracked CSs, together with their name and state. More...
 
void SetWorldAge (const AString &a_WorldName, cTickTimeLong a_Age)
 Sets the initial world age. More...
 

Protected Attributes

cCriticalSection m_CS
 Protects m_TrackedCriticalSections from multithreaded access. More...
 
int m_IntervalSec
 Number of secods for which the ages must be the same for the detection to trigger. More...
 
std::vector< std::pair< cCriticalSection *, AString > > m_TrackedCriticalSections
 CriticalSections that are tracked (their status output on deadlock). More...
 
WorldAges m_WorldAges
 
- Protected Attributes inherited from cIsThread
std::atomic< bool > m_ShouldTerminate
 The overriden Execute() method should check this value periodically and terminate if this is true. More...
 

Private Types

using Super = cIsThread
 

Detailed Description

Definition at line 23 of file DeadlockDetect.h.

Member Typedef Documentation

◆ Super

Definition at line 26 of file DeadlockDetect.h.

◆ WorldAges

typedef std::map<AString, sWorldAge> cDeadlockDetect::WorldAges
protected

Maps world name -> sWorldAge.

Definition at line 56 of file DeadlockDetect.h.

Constructor & Destructor Documentation

◆ cDeadlockDetect()

cDeadlockDetect::cDeadlockDetect ( void  )

Definition at line 23 of file DeadlockDetect.cpp.

◆ ~cDeadlockDetect()

cDeadlockDetect::~cDeadlockDetect ( )
overridevirtual

Definition at line 33 of file DeadlockDetect.cpp.

Member Function Documentation

◆ CheckWorldAge()

void cDeadlockDetect::CheckWorldAge ( const AString a_WorldName,
cTickTimeLong  a_Age 
)
protected

Checks if the world's age has changed, updates the world's stats; calls DeadlockDetected() if deadlock detected.

Definition at line 129 of file DeadlockDetect.cpp.

◆ DeadlockDetected()

void cDeadlockDetect::DeadlockDetected ( const AString a_WorldName,
cTickTimeLong  a_WorldAge 
)
protected

Called when a deadlock is detected in a world.

Aborts the server. a_WorldName is the name of the world whose age has triggered the detection. a_WorldAge is the age (in ticks) in which the world is stuck.

Definition at line 159 of file DeadlockDetect.cpp.

◆ Execute()

void cDeadlockDetect::Execute ( void  )
overrideprotectedvirtual

This function, overloaded by the descendants, is called in the new thread.

Implements cIsThread.

Definition at line 99 of file DeadlockDetect.cpp.

◆ ListTrackedCSs()

void cDeadlockDetect::ListTrackedCSs ( void  )
protected

Outputs a listing of the tracked CSs, together with their name and state.

Definition at line 173 of file DeadlockDetect.cpp.

◆ SetWorldAge()

void cDeadlockDetect::SetWorldAge ( const AString a_WorldName,
cTickTimeLong  a_Age 
)
protected

Sets the initial world age.

Definition at line 119 of file DeadlockDetect.cpp.

◆ Start()

void cDeadlockDetect::Start ( int  a_IntervalSec)

Starts the detection.

Hides cIsThread's Start, because we need some initialization

Definition at line 54 of file DeadlockDetect.cpp.

◆ TrackCriticalSection()

void cDeadlockDetect::TrackCriticalSection ( cCriticalSection a_CS,
const AString a_Name 
)

Adds the critical section for tracking.

Tracked CSs are listed, together with ownership details, when a deadlock is detected. A tracked CS must be untracked before it is destroyed. a_Name is an arbitrary name that is listed along with the CS in the output.

Definition at line 72 of file DeadlockDetect.cpp.

◆ UntrackCriticalSection()

void cDeadlockDetect::UntrackCriticalSection ( cCriticalSection a_CS)

Removes the CS from the tracking.

Definition at line 82 of file DeadlockDetect.cpp.

Member Data Documentation

◆ m_CS

cCriticalSection cDeadlockDetect::m_CS
protected

Protects m_TrackedCriticalSections from multithreaded access.

Definition at line 59 of file DeadlockDetect.h.

◆ m_IntervalSec

int cDeadlockDetect::m_IntervalSec
protected

Number of secods for which the ages must be the same for the detection to trigger.

Definition at line 68 of file DeadlockDetect.h.

◆ m_TrackedCriticalSections

std::vector<std::pair<cCriticalSection *, AString> > cDeadlockDetect::m_TrackedCriticalSections
protected

CriticalSections that are tracked (their status output on deadlock).

Protected against multithreaded access by m_CS.

Definition at line 63 of file DeadlockDetect.h.

◆ m_WorldAges

WorldAges cDeadlockDetect::m_WorldAges
protected

Definition at line 65 of file DeadlockDetect.h.


The documentation for this class was generated from the following files: