[squeak-dev] Events in HydraVM
Stephan Rudlof
sr at evolgo.de
Thu Feb 28 14:43:33 UTC 2008
Hello Igor,
thank you for your interesting explanations!
One remark:
On 28.02.2008 09:04, Igor Stasenko wrote:
> John M McIntosh asked me to make some overview on HydraVM internals -
> events subsystem.
> So, here it is. :)
>
>...
> About event handling function:
> this is the function which will be called when interpreter will
> interrupt for handling events, so in this function you have
> synchronized access to object memory, interpreter state e.t.c. and
> don't have to worry about concurrency.
> Also, function along with event payload are very convenient for
> determining context and what event means and what it will do.
> Instead of making dozens of event types, enumerating them.. then
> writing a case statements, it's doing a simple dispatch
> event->fn(interpreter, event); so, system are flexible and can handle
> events of any kind doing anything you want.
This makes it possible to elegantly switch between different event handling funcs: e.g. between a normal and a debugging one, without *any* debugging code in the normal one (by an event func var in the plugin, set by a plugin primitive, used by event posting code).
Regards,
Stephan
>
> As for example, suppose you wanna write a plugin which needs to post
> events to interpreter, but with your own, custom handling code, and
> with your event payload.
> So, declare an event in form:
>
> struct myEvent
> {
> struct vmEvent header;
> int myField1;
> int myField2;
> ..
> };
>
> Now to post event we simply can do:
>
> myEvent * event = malloc(sizeof(myEvent));
> event->header->fn = myHandler;
> event->myField1 = ...
> ....
>
> Now, a handler function:
>
> sqInt myHandler(struct Interpreter * intr, myEvent * evt)
> {
> ... do something nasty here, knowing that you can't be trapped by
> concurrency issues :)..
>
> free(evt); // release memory, allocated for event
> }
>
>
--
Stephan Rudlof
"Genius doesn't work on an assembly line basis.
You can't simply say, 'Today I will be brilliant.'"
-- Kirk, "The Ultimate Computer", stardate 4731.3
More information about the Squeak-dev
mailing list
|