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.
develop
Alexander Gavrilov 2012-04-03 13:29:59 +04:00
parent 444377f9db
commit 42a9b0a592
1 changed files with 17 additions and 0 deletions

@ -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