summaryrefslogtreecommitdiff
path: root/library/Core.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-04-03 13:29:59 +0400
committerAlexander Gavrilov2012-04-03 13:29:59 +0400
commit42a9b0a59271f80d512dde78407d3a07681b3421 (patch)
treea1ebad734e1af78786e0d75543fcb2d749054ef1 /library/Core.cpp
parent444377f9db0e5443433468cc13904bed5b343d40 (diff)
downloaddfhack-42a9b0a59271f80d512dde78407d3a07681b3421.tar.gz
dfhack-42a9b0a59271f80d512dde78407d3a07681b3421.tar.bz2
dfhack-42a9b0a59271f80d512dde78407d3a07681b3421.tar.xz
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.
Diffstat (limited to 'library/Core.cpp')
-rw-r--r--library/Core.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/library/Core.cpp b/library/Core.cpp
index ffc17472..b3c91034 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<mutex> 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<mutex> lock(d->AccessMutex);
+
+ assert(d->df_suspend_depth == 1000);
+ d->df_suspend_depth = 0;
+ }
+
out << std::flush;
// wake waiting tools