ruby: add magic "nolock " prefix to run ruby without Suspending main df

develop
jj 2012-10-12 11:12:31 +02:00
parent 424c37c0ea
commit 0547ee7f83
1 changed files with 22 additions and 11 deletions

@ -118,18 +118,8 @@ DFhackCExport command_result plugin_shutdown ( color_ostream &out )
return CR_OK; return CR_OK;
} }
// send a single ruby line to be evaluated by the ruby thread static command_result do_plugin_eval_ruby(color_ostream &out, const char *command)
DFhackCExport command_result plugin_eval_ruby( color_ostream &out, const char *command)
{ {
// if dlopen failed
if (!r_thread)
return CR_FAILURE;
// wrap all ruby code inside a suspend block
// if we dont do that and rely on ruby code doing it, we'll deadlock in
// onupdate
CoreSuspender suspend;
command_result ret; command_result ret;
// ensure ruby thread is idle // ensure ruby thread is idle
@ -159,6 +149,27 @@ DFhackCExport command_result plugin_eval_ruby( color_ostream &out, const char *c
return ret; return ret;
} }
// send a single ruby line to be evaluated by the ruby thread
DFhackCExport command_result plugin_eval_ruby( color_ostream &out, const char *command)
{
// if dlopen failed
if (!r_thread)
return CR_FAILURE;
if (!strncmp(command, "nolock ", 7)) {
// debug only!
// run ruby commands without locking the main thread
// useful when the game is frozen after a segfault
return do_plugin_eval_ruby(out, command+7);
} else {
// wrap all ruby code inside a suspend block
// if we dont do that and rely on ruby code doing it, we'll deadlock in
// onupdate
CoreSuspender suspend;
return do_plugin_eval_ruby(out, command);
}
}
DFhackCExport command_result plugin_onupdate ( color_ostream &out ) DFhackCExport command_result plugin_onupdate ( color_ostream &out )
{ {
if (!r_thread) if (!r_thread)