[Bf-committers] Wondering about the review of the command port patch...

Stéphane SOPPERA stephane.soppera at wanadoo.fr
Fri Sep 19 08:51:14 CEST 2008


Stéphane SOPPERA a écrit :
>   
>> +/**
>> +   busy waiting for new events.
>> +
>> +   Note: The blocking GHOST event processing is
>> +   implemented in the same way using busy waiting (polling)
>> +   on the GHOST event queue.  Doing the same on the Blender 
>> +   event queue makes it possible to also react to events
>> +   inserted into the Blender main event queue by parallel
>> +   threads - for example the Blender command port thread.
>> +
>> +   Added to make the command port work :)
>> +   (dietrich)
>> +*/
>> +static void wait_for_event()
>> +{
>> +	while (!mainqtest()) {
>> +		PIL_sleep_ms(5);          /* sleep for 5 milliseconds */
>> +		winlay_process_events(0); /* if there are events in the GHOST queue,
>> +									 (non-blocking polling of GHOST events) 
>> +									 preprocess them and copy them over
>> +									 into the Blender main event queue.
>> +								  */
>> +	}
>> +}
>>   
>>     
> Hi,
>
> Instead of this busy waiting with a 5ms sleep, wouldn't it be better to 
> use a pthread condition?
> http://www.humbug.org.au/talks/pthreads/pthread_cond.html
>   
Hi,

Just occured to me that at least on windows this is not feasable. Only 
the PostMessage can be used to solve this issue since the GetMessage has 
to be called on the "main" thread. So this is the technique that should 
be used:
> Finally, on windows, there is the PostMessage function that can be used 
> to post a message on the events queue of a thread, and using a WM_USER 
> message would be far easier than having to add a custom lock+condition. 
> I don't know XLib programming, maybe there is the equivalent functionality.
>   
I also had a quick look on GHOST_SystemX11 and particulary to the function:
    SleepTillEvent (blender\intern\ghost\intern\GHOST_SystemX11.cpp)
that seems to be used on X11 to make the equivalent of WaitMessage on 
windows.
Since this function uses a "select" call, it would be very easy to add 
second file descriptor to the select read list (such as the one of a 
pipe) to be able to break this wait when a thread wants to add a custom 
event in the blender events queue.

So there is no need of busy waiting on either windows or unix.

Regards,
Stéphane





More information about the Bf-committers mailing list