#197 wait 1 sec before exit infinite loop

This commit is contained in:
BADIM-PC\Vadim 2018-01-11 12:41:44 +03:00
parent 329a6bad0b
commit ea362a12e0
1 changed files with 12 additions and 1 deletions

View File

@ -821,18 +821,29 @@ static const struct{duk_c_function func; s32 params;} ApiFunc[] =
STATIC_ASSERT(api_func, COUNT_OF(ApiKeywords) == COUNT_OF(ApiFunc));
static u64 ForceExitCounter = 0;
s32 duk_timeout_check(void* udata)
{
tic_machine* machine = (tic_machine*)udata;
tic_tick_data* tick = machine->data;
return tick->forceExit && tick->forceExit(tick->data);
enum{Wait = 1000}; // 1 sec
if(ForceExitCounter)
return ForceExitCounter < tick->counter();
else if(tick->forceExit && tick->forceExit(tick->data))
ForceExitCounter = tick->counter() + Wait * 1000 / tick->freq();
return false;
}
static void initDuktape(tic_machine* machine)
{
closeJavascript((tic_mem*)machine);
ForceExitCounter = 0;
duk_context* duk = machine->js = duk_create_heap(NULL, NULL, NULL, machine, NULL);
{