lurking signals in EventSensor

Lex Spoon lex at cc.gatech.edu
Thu Jul 3 03:27:54 UTC 2003


John M McIntosh <johnmci at mac.com> wrote:
> Why, well I suspect, mostly because I've not found it yet, is that  
> under the right sequence of events the mouse
> over logic is hunting for cursor movement via say cursorPoint which  
> calls primMousePt which calls
> inputSemaphore signal, and stacks LOTS of excess signals on the  
> Semaphore, at which point the
> io processor loop consumes them. The issue here is LOTS, that this is  
> reflected in a glitchy pause as we
> grind though them.

In this situation, it seems like a good idea for the Smalltalk-level
code to do initSignals whenever it wakes up from a semaphore.  So maybe
this would solve the problem you've observed:

EventSensor>>ioProcess
	"Run the i/o process"
	| eventBuffer type |
	eventBuffer _ Array new: 8.
	[true] whileTrue:[
		[self primGetNextEvent: eventBuffer.
		type _ eventBuffer at: 1.
		type = EventTypeNone] whileFalse:[self processEvent: eventBuffer].
		inputSemaphore waitTimeoutMSecs: EventPollFrequency.

		"=====NEW LINE OF CODE RIGHT HERE========"
		inputSemaphore initSignals.
	].


I'm confused why there would be *tons* of signals, though.  Could there
be more than one signal per event?  Reading in the events is sure to
take much longer than waiting on a semaphore, and so at equal numbers
the semaphore waiting would be unlikely to be a problem.  Perhaps there
really are just a lot of events?

If you are thinking of refactoring it, I might suggest another setup of
all this code.  Simply have EventSensor>>nextEvent ask the VM for an
event, and if the primitive fails you synthesize an event. 
Additionally, the VM's need to be sure that whenever a legacy polling
primitive is called, they clear their event queue.  (They need to do
something like this, anyway, in order to deal with legacy images.) 
That's it.  This simple approach works for all combinations of old/new
image/VM.  

	new VM, new image:   nirvana
	new VM, old image:  the legacy methods are used,and the queues get
cleared automatically
	old VM, new image:  events are synthesized using the primitives
	old VM, old image:  uses polling primitives, duh


As one caveat, EventSensor needs to be careful to simulate the legacy
polling methods by remember the newest event; if it uses the real
primitive, the VM might clear the event queue and lose events.


Lex



More information about the Squeak-dev mailing list