[vlc-devel] [PATCH 2/2] threads: winstore: Use native wait condition implementation

Hugo Beauzée-Luyssen hugo at beauzee.fr
Sun Nov 23 14:42:03 CET 2014



> On 23 Nov 2014, at 00:03, Jean-Baptiste Kempf <jb at videolan.org> wrote:
> 
> WIN32_WINNT >= 0x600 more than WinSTore, no?
> 
> On 20 Nov, Hugo Beauzée-Luyssen wrote :
>> ---
>> include/vlc_threads.h |  4 ++++
>> src/win32/thread.c    | 44 +++++++++++++++++++++++++++++++++++++++-----
>> 2 files changed, 43 insertions(+), 5 deletions(-)
>> 
>> diff --git a/include/vlc_threads.h b/include/vlc_threads.h
>> index 00435cb..45a733d 100644
>> --- a/include/vlc_threads.h
>> +++ b/include/vlc_threads.h
>> @@ -57,7 +57,11 @@ typedef struct
>> #define VLC_STATIC_MUTEX { false, { { false, 0 } } }
>> typedef struct
>> {
>> +#ifndef VLC_WINSTORE_APP
>>     HANDLE   handle;
>> +#else
>> +    CONDITION_VARIABLE cond;
>> +#endif
>>     unsigned clock;
>> } vlc_cond_t;
>> #define VLC_STATIC_COND { 0, 0 }
>> diff --git a/src/win32/thread.c b/src/win32/thread.c
>> index 1cb2ee0..32fef2b 100644
>> --- a/src/win32/thread.c
>> +++ b/src/win32/thread.c
>> @@ -202,10 +202,14 @@ enum
>> 
>> static void vlc_cond_init_common (vlc_cond_t *p_condvar, unsigned clock)
>> {
>> +#ifndef VLC_WINSTORE_APP
>>     /* Create a manual-reset event (manual reset is needed for broadcast). */
>>     p_condvar->handle = CreateEvent (NULL, TRUE, FALSE, NULL);
>>     if (!p_condvar->handle)
>>         abort();
>> +#else
>> +    InitializeConditionVariable(&p_condvar->cond);
>> +#endif
>>     p_condvar->clock = clock;
>> }
>> 
>> @@ -221,7 +225,9 @@ void vlc_cond_init_daytime (vlc_cond_t *p_condvar)
>> 
>> void vlc_cond_destroy (vlc_cond_t *p_condvar)
>> {
>> +#ifndef VLC_WINSTORE_APP
>>     CloseHandle (p_condvar->handle);
>> +#endif
>> }
>> 
>> void vlc_cond_signal (vlc_cond_t *p_condvar)
>> @@ -229,8 +235,12 @@ void vlc_cond_signal (vlc_cond_t *p_condvar)
>>     if (!p_condvar->clock)
>>         return;
>> 
>> +#ifndef VLC_WINSTORE_APP
>>     /* This is suboptimal but works. */
>>     vlc_cond_broadcast (p_condvar);
>> +#else
>> +    WakeConditionVariable(&p_condvar->cond);
>> +#endif
>> }
>> 
>> void vlc_cond_broadcast (vlc_cond_t *p_condvar)
>> @@ -238,20 +248,25 @@ void vlc_cond_broadcast (vlc_cond_t *p_condvar)
>>     if (!p_condvar->clock)
>>         return;
>> 
>> +#ifndef VLC_WINSTORE_APP
>>     /* Wake all threads up (as the event HANDLE has manual reset) */
>>     SetEvent (p_condvar->handle);
>> +#else
>> +    WakeAllConditionVariable(&p_condvar->cond);
>> +#endif
>> }
>> 
>> void vlc_cond_wait (vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex)
>> {
>> -    DWORD result;
>> -
>>     if (!p_condvar->clock)
>>     {   /* FIXME FIXME FIXME */
>> -        msleep (50000);
>> +        msleep(50000);
>>         return;
>>     }
>> 
>> +#ifndef VLC_WINSTORE_APP
>> +    DWORD result;
>> +
>>     do
>>     {
>>         vlc_testcancel ();
>> @@ -262,12 +277,16 @@ void vlc_cond_wait (vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex)
>>     while (result == WAIT_IO_COMPLETION);
>> 
>>     ResetEvent (p_condvar->handle);
>> +#else
>> +    vlc_cond_timedwait(p_condvar, p_mutex, INFINITE);
>> +#endif
>> }
>> 
>> int vlc_cond_timedwait (vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex,
>>                         mtime_t deadline)
>> {
>>     DWORD result;
>> +    DWORD delay;
>> 
>>     do
>>     {
>> @@ -292,14 +311,29 @@ int vlc_cond_timedwait (vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex,
>>         if( total < 0 )
>>             total = 0;
>> 
>> -        DWORD delay = (total > 0x7fffffff) ? 0x7fffffff : total;
>> -        vlc_mutex_unlock (p_mutex);
>> +        delay = (total > 0x7fffffff) ? 0x7fffffff : total;
>> +#ifndef VLC_WINSTORE_APP
>> +        vlc_mutex_unlock(p_mutex);
>>         result = vlc_WaitForSingleObject (p_condvar->handle, delay);
>>         vlc_mutex_lock (p_mutex);
>>     }
>>     while (result == WAIT_IO_COMPLETION);
>> 
>>     ResetEvent (p_condvar->handle);
>> +#else
>> +        DWORD new_delay = 50;
>> +        if (new_delay > delay)
>> +            new_delay = delay;
>> +        if (SleepConditionVariableCS(&p_condvar->cond, &p_mutex->mutex, new_delay))
>> +            return 0;
>> +        if (delay != INFINITE)
>> +            delay -= new_delay;
>> +        result = GetLastError();
>> +        if (isCancelled())
>> +            result = WAIT_IO_COMPLETION;
>> +    }
>> +    while (delay);
>> +#endif
> 

Indeed, this can be used starting with vista. Currently that’s only our WinRT build, but it shouldn’t be related code-wise.
I’ll update the patch.

Regards,

— 
Hugo Beauzée-Luyssen
hugo at beauzee.fr





More information about the vlc-devel mailing list