How to implement events on Unix?

John M McIntosh johnmci at smalltalkconsulting.com
Thu Feb 8 03:07:05 UTC 2001


>Hi!



>I think, there're two important functions:  One to tell the VM about 
>a semaphore on which - I guess - the Smalltalk code will wait for 
>the next event.  And another to retrieve that event from the VM. 
>The mac VM seems to allocate a circular buffer with 1024 elements to 
>store elements.  However, I wonder why the code to signal the 
>semaphore is commented out.  Doesn't that means, the whole event 
>stuff doesn't work yet?


Well the reason the signal semaphore is commented out is because

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.
		Preferences higherPerformance ifTrue: [
			EventPollFrequency _ (EventPollFrequency * 
1.5) rounded min: 500.
		].
	].

What happens here is that if primGetNextEvent doesn't return an event 
then we wait 20ms and try again. So technically we are polling... 
Because of this having the signal semaphore isn't really required in 
the Mac VM.

Now in some respects this is an interesting hunk of code because it 
assume the VM requires a poll to look for events, versus just waiting 
on the semaphore forever.

In the mac code VM code it does
int ioGetNextEvent(sqInputEvent *evt) {
	if (eventBufferGet == eventBufferPut) {
		ioProcessEvents();
	}

Which triggers a mac os waitnextevent call not more than 60 times a 
second, which looks for and builds the event we put on the event 
buffer.

I've been debating if to either

1) Explore the Carbon event manager which is event driven
2) Use the processor package and run a UI thread and the Squeak thread.

But time is always short.


-- 
--
===========================================================================
John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================
Custom Macintosh programming & various Smalltalk dialects
PGP Key: DSS/Diff/46FC3BE6
Fingerprint=B22F 7D67 92B7 5D52 72D7  E94A EE69 2D21 46FC 3BE6
===========================================================================





More information about the Squeak-dev mailing list