[vlc-devel] [PATCH 5/6] qt4: Run mainloop on the main thread on OSX

Juho Vähä-Herttua juhovh at iki.fi
Sat Jul 24 23:48:28 CEST 2010


On 24.7.2010, at 23.56, Rémi Denis-Courmont wrote:
> Le samedi 24 juillet 2010 23:31:13 Juho Vähä-Herttua, vous avez écrit :
>> @@ -335,9 +344,14 @@ static int Open( vlc_object_t *p_this, bool
>> isDialogProvider ) return VLC_ENOMEM;
>>     }
>> 
>> -    /* */
>> +#ifndef Q_WS_MAC
>> +    /* Wait until the interface is initialized, This is to avoid a race
>> +     * condition where playlist is started before the interface is
>> initialized +     * and therefore first video is not run in the embedded
>> window. On Mac the +     * interface is run on main thread so this problem
>> doesn't exist, playlist +     * needs to be started explicitly for Mac OS
>> X. */
>>     vlc_sem_wait (&ready);
>> -    vlc_sem_destroy (&ready);
> 
> Seems wrong.

Misunderstanding probably, I'd welcome a better wording to explain what the semaphore there is actually doing.

>> +#endif
>> 
>>     if( !p_sys->b_isDialogProvider )
>>     {
>> @@ -376,6 +390,7 @@ static void Close( vlc_object_t *p_this )
>>     QVLCApp::triggerQuit();
>> 
>>     vlc_join (p_sys->thread, NULL);
>> +    vlc_sem_destroy (&ready);
>> #ifdef Q_WS_X11
>>     free (x11_display);
>>     x11_display = NULL;
>> @@ -460,7 +475,7 @@ static void *Thread( void *obj )
>>     /* Explain how to show a dialog :D */
>>     p_intf->pf_show_dialog = ShowDialog;
>> 
>> -    /* */
>> +    /* Notify that the interface is initialized */
>>     vlc_sem_post (&ready);
>> 
>>     /* Last settings */
>> @@ -478,6 +493,9 @@ static void *Thread( void *obj )
>>     /* Launch */
>>     app.exec();
>> 
>> +    /* Notify that the interface is cleaned up */
>> +    vlc_sem_post (&ready);
>> +
>>     /* Delete the application automatically */
>>     return NULL;
>> }
>> @@ -524,6 +542,20 @@ static void Cleanup( void *obj )
>>     MainInputManager::killInstance();
>> }
>> 
>> +static void *Monitor( void *obj )
>> +{
>> +    intf_thread_t *p_intf = (intf_thread_t *)obj;
>> +
>> +    /* Wait for interface to initialize */
>> +    vlc_sem_wait (&ready);
>> +
>> +    /* Wait for interface to cleanup */
>> +    vlc_sem_wait (&ready);
>> +
>> +    msg_Dbg( p_intf, "Monitor thread finished" );
>> +    return NULL;
>> +}
> 
> That thread looks quite useless.

It looks quite useless, but I plan to use it to start the playlist in the middle of those two sem_wait calls. Also having this thread made it possible to avoid larger changes in the Close() function, because vlc_join works just like before, even though mainloop is actually run on main thread. I know you don't like extra threads, but then again it doesn't really increase the thread count vs. the non-hack code. The other run_on_first_thread hack does though...


Juho

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4215 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20100725/f77daa7d/attachment.bin>


More information about the vlc-devel mailing list