summaryrefslogtreecommitdiffstats
path: root/src/DeadlockDetect.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2017-01-17 22:38:04 +0100
committerMattes D <github@xoft.cz>2017-01-18 09:03:05 +0100
commit7cc3fb098df221f083da1d81d2327a0a5f22edf5 (patch)
treede9232cbf239800ea1e7a71cf52086509a9472ea /src/DeadlockDetect.cpp
parentDebuggers: Added a deadlock simulation command. (diff)
downloadcuberite-7cc3fb098df221f083da1d81d2327a0a5f22edf5.tar
cuberite-7cc3fb098df221f083da1d81d2327a0a5f22edf5.tar.gz
cuberite-7cc3fb098df221f083da1d81d2327a0a5f22edf5.tar.bz2
cuberite-7cc3fb098df221f083da1d81d2327a0a5f22edf5.tar.lz
cuberite-7cc3fb098df221f083da1d81d2327a0a5f22edf5.tar.xz
cuberite-7cc3fb098df221f083da1d81d2327a0a5f22edf5.tar.zst
cuberite-7cc3fb098df221f083da1d81d2327a0a5f22edf5.zip
Diffstat (limited to 'src/DeadlockDetect.cpp')
-rw-r--r--src/DeadlockDetect.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/DeadlockDetect.cpp b/src/DeadlockDetect.cpp
index 525dc8118..df14e610b 100644
--- a/src/DeadlockDetect.cpp
+++ b/src/DeadlockDetect.cpp
@@ -30,6 +30,27 @@ cDeadlockDetect::cDeadlockDetect(void) :
+cDeadlockDetect::~cDeadlockDetect()
+{
+ // Check that all tracked CSs have been removed, report any remaining:
+ cCSLock lock(m_CS);
+ if (!m_TrackedCriticalSections.empty())
+ {
+ LOGWARNING("DeadlockDetect: Some CS objects (%u) haven't been removed from tracking", static_cast<unsigned>(m_TrackedCriticalSections.size()));
+ for (const auto & tcs: m_TrackedCriticalSections)
+ {
+ LOGWARNING(" CS %p / %s",
+ static_cast<void *>(tcs.first),
+ tcs.second.c_str()
+ );
+ }
+ }
+}
+
+
+
+
+
bool cDeadlockDetect::Start(int a_IntervalSec)
{
m_IntervalSec = a_IntervalSec;
@@ -61,6 +82,33 @@ bool cDeadlockDetect::Start(int a_IntervalSec)
+void cDeadlockDetect::TrackCriticalSection(cCriticalSection & a_CS, const AString & a_Name)
+{
+ cCSLock lock(m_CS);
+ m_TrackedCriticalSections.emplace_back(std::make_pair(&a_CS, a_Name));
+}
+
+
+
+
+
+void cDeadlockDetect::UntrackCriticalSection(cCriticalSection & a_CS)
+{
+ cCSLock lock(m_CS);
+ for (auto itr = m_TrackedCriticalSections.begin(), end = m_TrackedCriticalSections.end(); itr != end; ++itr)
+ {
+ if (itr->first == &a_CS)
+ {
+ m_TrackedCriticalSections.erase(itr);
+ return;
+ }
+ }
+}
+
+
+
+
+
void cDeadlockDetect::Execute(void)
{
// Loop until the signal to terminate:
@@ -140,6 +188,7 @@ void cDeadlockDetect::DeadlockDetected(const AString & a_WorldName, Int64 a_Worl
LOGERROR("Deadlock detected: world %s has been stuck at age %lld. Aborting the server.",
a_WorldName.c_str(), static_cast<long long>(a_WorldAge)
);
+ ListTrackedCSs();
ASSERT(!"Deadlock detected");
abort();
}
@@ -147,3 +196,19 @@ void cDeadlockDetect::DeadlockDetected(const AString & a_WorldName, Int64 a_Worl
+
+void cDeadlockDetect::ListTrackedCSs(void)
+{
+ cCSLock lock(m_CS);
+ for (const auto & cs: m_TrackedCriticalSections)
+ {
+ LOG("CS at %p, %s: RecursionCount = %d, ThreadIDHash = %04llx",
+ static_cast<void *>(cs.first), cs.second.c_str(),
+ cs.first->m_RecursionCount, static_cast<UInt64>(std::hash<std::thread::id>()(cs.first->m_OwningThreadID))
+ );
+ }
+}
+
+
+
+