[vlc-devel] commit: Do not assume that Open and Close are called in the same thread ( Rémi Denis-Courmont )

git version control git at videolan.org
Sat Feb 20 15:57:13 CET 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Feb 20 16:56:49 2010 +0200| [7553630d1a8acd8a02ab7eb6e0cf2570732c95f6] | committer: Rémi Denis-Courmont 

Do not assume that Open and Close are called in the same thread

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

 modules/gui/qt4/qt4.cpp |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index b7e456f..19bfafa 100644
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -271,7 +271,11 @@ static vlc_sem_t ready;
 #ifdef Q_WS_X11
 static char *x11_display = NULL;
 #endif
-static vlc_mutex_t lock = VLC_STATIC_MUTEX;
+static struct
+{
+    vlc_mutex_t lock;
+    bool busy;
+} one = { VLC_STATIC_MUTEX, false };
 
 /*****************************************************************************
  * Module callbacks
@@ -294,7 +298,12 @@ static int Open( vlc_object_t *p_this, bool isDialogProvider )
     putenv( (char *)"XLIB_SKIP_ARGB_VISUALS=1" );
 #endif
 
-    if (vlc_mutex_trylock (&lock))
+    bool busy;
+    vlc_mutex_lock (&one.lock);
+    busy = one.busy;
+    one.busy = true;
+    vlc_mutex_unlock (&one.lock);
+    if (busy)
     {
         msg_Err (p_this, "cannot start Qt4 multiple times");
         return VLC_EGENERIC;
@@ -312,7 +321,9 @@ static int Open( vlc_object_t *p_this, bool isDialogProvider )
     if( vlc_clone( &p_sys->thread, Thread, p_intf, VLC_THREAD_PRIORITY_LOW ) )
     {
         delete p_sys;
-        vlc_mutex_unlock (&lock);
+        vlc_mutex_lock (&one.lock);
+        one.busy = false;
+        vlc_mutex_unlock (&one.lock);
         return VLC_ENOMEM;
     }
 
@@ -354,7 +365,9 @@ static void Close( vlc_object_t *p_this )
 
     vlc_join (p_sys->thread, NULL);
     delete p_sys;
-    vlc_mutex_unlock (&lock);
+    vlc_mutex_lock (&one.lock);
+    one.busy = false;
+    vlc_mutex_unlock (&one.lock);
 #ifdef Q_WS_X11
     free (x11_display);
 #endif




More information about the vlc-devel mailing list