[vlc-commits] win32/window: simplify using semaphore

Rémi Denis-Courmont git at videolan.org
Tue Feb 4 19:02:11 CET 2020


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Feb  3 22:50:18 2020 +0200| [bead211b6392917c67fae300fc029bfa4273fc9e] | committer: Rémi Denis-Courmont

win32/window: simplify using semaphore

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=bead211b6392917c67fae300fc029bfa4273fc9e
---

 modules/video_output/win32/window.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/modules/video_output/win32/window.c b/modules/video_output/win32/window.c
index 6afb75be79..ba14d9fb97 100644
--- a/modules/video_output/win32/window.c
+++ b/modules/video_output/win32/window.c
@@ -50,8 +50,7 @@ typedef struct vout_window_sys_t
 {
     vlc_thread_t thread;
     vlc_mutex_t  lock;
-    vlc_cond_t   wait;
-    bool         b_ready;
+    vlc_sem_t    ready;
 
     HWND hwnd;
 
@@ -485,8 +484,8 @@ static void Close(vout_window_t *wnd)
     if (sys->hwnd)
         PostMessage( sys->hwnd, WM_CLOSE, 0, 0 );
     vlc_join(sys->thread, NULL);
+    vlc_sem_destroy( &sys->ready );
     vlc_mutex_destroy( &sys->lock );
-    vlc_cond_destroy( &sys->wait );
 
     HINSTANCE hInstance = GetModuleHandle(NULL);
     UnregisterClass( sys->class_main, hInstance );
@@ -633,10 +632,7 @@ static void *EventThread( void *p_this )
                     hInstance,            /* handle of this program instance */
                     wnd );                           /* send vd to WM_CREATE */
 
-    vlc_mutex_lock( &sys->lock );
-    sys->b_ready = true;
-    vlc_cond_signal( &sys->wait );
-    vlc_mutex_unlock( &sys->lock );
+    vlc_sem_post( &sys->ready );
 
     if (sys->hwnd == NULL)
     {
@@ -734,8 +730,7 @@ static int Open(vout_window_t *wnd)
         return VLC_EGENERIC;
     }
     vlc_mutex_init( &sys->lock );
-    vlc_cond_init( &sys->wait );
-    sys->b_ready = false;
+    vlc_sem_init( &sys->ready, 0 );
 
     wnd->sys = sys;
     if( vlc_clone( &sys->thread, EventThread, wnd, VLC_THREAD_PRIORITY_LOW ) )
@@ -744,18 +739,13 @@ static int Open(vout_window_t *wnd)
         return VLC_EGENERIC;
     }
 
-    vlc_mutex_lock( &sys->lock );
-    while( !sys->b_ready )
-    {
-        vlc_cond_wait( &sys->wait, &sys->lock );
-    }
+    vlc_sem_wait( &sys->ready );
+
     if (sys->hwnd == NULL)
     {
-        vlc_mutex_unlock( &sys->lock );
         Close(wnd);
         return VLC_EGENERIC;
     }
-    vlc_mutex_unlock( &sys->lock );
 
     wnd->sys = sys;
     wnd->type = VOUT_WINDOW_TYPE_HWND;



More information about the vlc-commits mailing list