From 42a9b0a59271f80d512dde78407d3a07681b3421 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Tue, 3 Apr 2012 13:29:59 +0400 Subject: [PATCH] Make Core::Suspend safe in plugin_onupdate by pretending to hold the lock. It is in essence true that OnUpdate owns the suspend lock, so expose it officially to the recursive suspend lock mechanics. --- library/Core.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/library/Core.cpp b/library/Core.cpp index ffc174721..b3c91034f 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -868,6 +868,15 @@ int Core::Update() color_ostream_proxy out(con); + // Pretend this thread has suspended the core in the usual way + { + lock_guard lock(d->AccessMutex); + + assert(d->df_suspend_depth == 0); + d->df_suspend_thread = this_thread::get_id(); + d->df_suspend_depth = 1000; + } + // detect if the game was loaded or unloaded in the meantime void *new_wdata = NULL; void *new_mapdata = NULL; @@ -922,6 +931,14 @@ int Core::Update() // notify all the plugins that a game tick is finished plug_mgr->OnUpdate(out); + // Release the fake suspend lock + { + lock_guard lock(d->AccessMutex); + + assert(d->df_suspend_depth == 1000); + d->df_suspend_depth = 0; + } + out << std::flush; // wake waiting tools