[Vm-dev] Win32 Event VM prototype

Andreas Raab andreas.raab at gmx.de
Sat Nov 14 20:52:33 UTC 2009

Stephen Pair wrote:
> You would call sendMessage() in response to Windows messages (it would 
> do nothing but safely and quickly enqueue messages for interpret()). 
> You could have a third call, waitUntilRunnable() and then you would 
> have a loop in an OS level thread that repeatedly calls 
> waitUntilRunnable() followed by interpret().  The Windows messages would 
> be calling sendMessage() to unblock waitUntilRunnable() and queue up 
> work for interpret().

Interestingly, we have all that just under different names. The 
sendMessage() call is implemented in C (via recordMouseEvent, 
recordKeyboardEvent etc) in such that its purpose is to "safely and 
quickly enqueues the nessage for interpret" ;-)

The function waitUntilRunnable() is implemented implicitly via having 
interpret call from the MainWndProc (which isn't called unless there's 
an event) but in an earlier version I wrote a more explicit loop like:

   while(1) {
     /* here goes waitUntilRunnable */
     /* and finally interpret() */

The issue with recursion is not as difficult as it might seem. The 
important thing (as you said) is knowing when a callback is "safe". And 
that's actually quite easy to determine - callbacks are safe if and only 
if you're in a primitive because only then all necessary interpreter 
state is sufficiently externalized. The callbackEnter implementation 
already makes use of that and I just haven't adapted all the necessary 
code. (I did prevent callbacks via ioProcessEvents since this is called 
from checkForInterrupts in strange places but that doesn't seem to be 

   - Andreas

More information about the Vm-dev mailing list