nyaapa has asked for the wisdom of the Perl Monks concerning the following question:
and c-part_push_timeout_stack(); local $SIG{USR1} = sub { _raise_alarm }; local $SIG{ALRM} = sub { _calc_evals_count_to_die(); _raise_alarm(); }; alarm($time); eval { $work->() }; _pop_timeout_stack();
void _push_timeout_stack() { timeout_stack* current = (timeout_stack*) calloc (1, sizeof(ti +meout_stack)); current->prev = stack; current->scope = PL_curstackinfo; current->nearest_block = &cxstack[cxstack_ix]; stack = current; } void _pop_timeout_stack() { if ( stack ) { timeout_stack* current = stack; stack = stack->prev; free(current); } } void _raise_alarm() { if ( evals_to_die-- ) { PL_psig_pend[SIGUSR1]++; PL_sig_pending = 1; croak("TIMEDOUT"); } } void _calc_evals_count_to_die() { evals_to_die = 0; bool cont = 1; int i = 0; PERL_SI * _cxstack = PL_curstackinfo; while ( cont ) { for (i = _cxstack->si_cxix; i >= 0 && cont; i--) { register const PERL_CONTEXT *cx = &_cxstack->si_cxstac +k[i]; if ( cx == stack->nearest_block ) cont = 0; else if ( CxTYPE(cx) == CXt_EVAL ) evals_to_die++; } if ( cont && (cont = _cxstack != stack->scope) ) _cxstack = _cxstack->si_prev; } if ( evals_to_die ) evals_to_die--; printf("Calced %d evals to pop\n", evals_to_die); }
|
|---|