summaryrefslogtreecommitdiffstats
path: root/source/DeadlockDetect.h
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2013-08-15 10:56:52 +0200
committerMattes D <github@xoft.cz>2013-08-15 10:56:52 +0200
commit1a52e89177a907b5d23d3e72f78d30a333da4bfe (patch)
tree8f2783d06d423361b02457c77f90d6ec874a5191 /source/DeadlockDetect.h
parentMerge pull request #91 from tigerw/master (diff)
parentAdded simple deadlock detection code. (diff)
downloadcuberite-1a52e89177a907b5d23d3e72f78d30a333da4bfe.tar
cuberite-1a52e89177a907b5d23d3e72f78d30a333da4bfe.tar.gz
cuberite-1a52e89177a907b5d23d3e72f78d30a333da4bfe.tar.bz2
cuberite-1a52e89177a907b5d23d3e72f78d30a333da4bfe.tar.lz
cuberite-1a52e89177a907b5d23d3e72f78d30a333da4bfe.tar.xz
cuberite-1a52e89177a907b5d23d3e72f78d30a333da4bfe.tar.zst
cuberite-1a52e89177a907b5d23d3e72f78d30a333da4bfe.zip
Diffstat (limited to 'source/DeadlockDetect.h')
-rw-r--r--source/DeadlockDetect.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/source/DeadlockDetect.h b/source/DeadlockDetect.h
new file mode 100644
index 000000000..bbd76826a
--- /dev/null
+++ b/source/DeadlockDetect.h
@@ -0,0 +1,70 @@
+
+// DeadlockDetect.h
+
+// Declares the cDeadlockDetect class that tries to detect deadlocks and aborts the server when it detects one
+
+/*
+This class simply monitors each world's m_WorldAge, which is expected to grow on each tick.
+If the world age doesn't grow for several seconds, it's either because the server is super-overloaded,
+or because the world tick thread hangs in a deadlock. We presume the latter and therefore kill the server.
+Once we learn to write crashdumps programmatically, we should do so just before killing, to enable debugging.
+*/
+
+
+
+#pragma once
+
+#include "OSSupport/IsThread.h"
+
+
+
+
+
+class cDeadlockDetect :
+ public cIsThread
+{
+ typedef cIsThread super;
+
+public:
+ cDeadlockDetect(void);
+
+ /// Starts the detection. Hides cIsThread's Start, because we need some initialization
+ bool Start(void);
+
+ /// Stops the detection. Hides cIsThread's Stop, because we need to signal m_EvtTerminate
+ void Stop(void);
+
+protected:
+ struct sWorldAge
+ {
+ /// Last m_WorldAge that has been detected in this world
+ Int64 m_Age;
+
+ /// Number of cycles for which the age has been the same
+ int m_NumCyclesSame;
+ } ;
+
+ /// Maps world name -> sWorldAge
+ typedef std::map<AString, sWorldAge> WorldAges;
+
+ WorldAges m_WorldAges;
+
+ cEvent m_EvtTerminate;
+
+
+ // cIsThread overrides:
+ virtual void Execute(void) override;
+
+ /// Sets the initial world age
+ void SetWorldAge(const AString & a_WorldName, Int64 a_Age);
+
+ /// Checks if the world's age has changed, updates the world's stats; calls DeadlockDetected() if deadlock detected
+ void CheckWorldAge(const AString & a_WorldName, Int64 a_Age);
+
+ /// Called when a deadlock is detected. Aborts the server.
+ void DeadlockDetected(void);
+} ;
+
+
+
+