Some more: This is where the code for checking for interrupt is generated
(defun maybe-generate-interrupt-check ()
(unless (> *speed* *safety*)
(let ((label1 (gensym)))
(emit-getstatic +lisp+ "interrupted" :boolean)
(emit 'ifeq label1)
(emit-invokestatic +lisp+ "handleInterrupt" nil nil)
(label label1))))
I'm thinking, since interrupt-lisp isn't used anyways, modify it to take a thread argument.
In interrupt-lisp, call setInterrupted with that thread.
In Lisp.java change the type of interrupted and change setInterrupted to take a thread argument, setting Lisp.interrupted to it.
Then, in the maybe-generate-interrupt-check don't Lisp.interrupted check as boolean, check if eq to
current thread. The current thread can be made accessible adding (ensure-thread-var-initialized), which puts it into a local at the beginning of the function. Access it with (aload *thread*) which puts it on the stack. I think this means that the lines underlined above get replaced with.
(ensure-thread-var-initialized)
(emit-getstatic +lisp+ "interrupted" +lisp-thread+)
(aload *thread*)
(emit 'if_acmpne label1)
In Lisp.handleInterrupts it's setInterrupted(null) vs setInterrrupted(false);
As stated, this mechanism is strictly to enable control-c.
However, maybe we could have it help thread-interrupt respond more quickly. in Lisp.handleInterrupts.
check thread.isInterrupted and call processThreadInterrupts (the thing that is done now) otherwise break.
Have the implementation of thread-interrupt do what it does now and also call interrupt-lisp to get it noticed.
---
I haven't tried this. Mostly I'm fumbling around trying to get enough information to do this. I don't know java byte code except what I learned researching this.
I don't know if there are pitfalls. I don't know why something like this wouldn't have been done in the first place.
The only thing I can currently think of is that there could be a race condition on setting Lisp.interrupted.
The consequence of that is that if there were two quick thread-interrupts, only one of the threads would
do the quick response. The other would be processed in the way it currently is.
Anyways, comments solicited.
Alan