Event handling currently works for all run cores[1] except JIT.

The JIT core can't use the schemes described below, but we could:
1) explicitely insert checks, if events are to be handled
1a) everywhere or
1b) in places like described below under [1] c)
2) Patch the native opcodes at these places with e.g. int3 (SIG_TRAP, debugger hook) cpu instruction and catch the trap. Running the event handler (sub) from there should be safe, as we are in a consistent state in the "run loop".
3) more ideas?


1) of course slows down execution of all JIT code, 2) is platform/architecture dependent, but JIT code is that anyway.

Comments welcome,
leo


[1]
a) Run cores with an opcode dispatch table get a new dispatch table, where all entries point to the event handling code
b) The switch core checks at the beginning of the switch statement.
c) Prederefed run cores get the opcode stream patched, where back-ward branches and invoke or such[2] are replaced with event-check opcodes.


While a) and c) is run async from the event thread, it shouldn't cause problems, because (assuming atomic word-access) either the old function table/opcode pointer is visible or already the new, there is no inconsistent state.

Events using a) or b) are handled instantly, while c) events get handled some (probably very short time) after they were scheduled.

[2] Explicit hints from the ops-files, where to check events would simplify that. E.g.

op event invoke()
op event_after sleep(..)



Reply via email to