fix bad behavior of time_out by making sure interrupts are disabled during critical operation, up
to setting a throw.
This commit is contained in:
parent
c3974d49eb
commit
f3e4148511
@ -24,15 +24,38 @@
|
|||||||
%
|
%
|
||||||
% not the nicest program I've ever seen.
|
% not the nicest program I've ever seen.
|
||||||
%
|
%
|
||||||
|
%
|
||||||
|
% I cannot use setup_call_cleanup because I can only take interrupts *after* I set up
|
||||||
|
% the catcher, so I have to do the dirty deed myself.
|
||||||
|
%
|
||||||
time_out(Goal, Time, Result) :-
|
time_out(Goal, Time, Result) :-
|
||||||
T is Time//1000,
|
T is Time//1000,
|
||||||
UT is (Time mod 1000)*1000,
|
UT is (Time mod 1000)*1000,
|
||||||
|
yap_hacks:disable_interrupts,
|
||||||
% enable alarm
|
% enable alarm
|
||||||
alarm(T.UT,throw(time_out),_),
|
alarm(T.UT,throw(time_out),_),
|
||||||
% launch goal and wait for signal
|
% launch goal and wait for signal
|
||||||
call_cleanup(
|
catch( run_goal(Goal, Result0),
|
||||||
catch( ( Result0 = success, once(Goal) ),
|
|
||||||
time_out,
|
time_out,
|
||||||
Result0 = time_out ),
|
Result0 = time_out ),
|
||||||
alarm(0,_,_) ),
|
|
||||||
Result = Result0.
|
Result = Result0.
|
||||||
|
|
||||||
|
run_goal(Goal, Result0) :-
|
||||||
|
% we can only enable interrupts after alarm was been enabled.
|
||||||
|
yap_hacks:enable_interrupts,
|
||||||
|
Result0 = success,
|
||||||
|
call(Goal),
|
||||||
|
!,
|
||||||
|
% make sure we're not getting an extraneous interrupt if we terminate early....
|
||||||
|
yap_hacks:disable_interrupts.
|
||||||
|
alarm(0,_,_),
|
||||||
|
true.
|
||||||
|
run_goal(Goal, Result0) :-
|
||||||
|
yap_hacks:disable_interrupts,
|
||||||
|
% make sure we're not getting an extraneous interrupt if we terminate early....
|
||||||
|
alarm(0,_,_),
|
||||||
|
fail.
|
||||||
|
|
||||||
|
complete_time_out :-
|
||||||
|
alarm(0,_,_),
|
||||||
|
yap_hacks:enable_interrupts.
|
||||||
|
Reference in New Issue
Block a user