[vlc-devel] commit: Qt4: fail cleanly if started multiple times (instead of crashing) ( Rémi Denis-Courmont )

git version control git at videolan.org
Sat Feb 20 15:52:24 CET 2010


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

Qt4: fail cleanly if started multiple times (instead of crashing)

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

 modules/gui/qt4/qt4.cpp |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index 24a3219..b7e456f 100644
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -271,6 +271,7 @@ static vlc_sem_t ready;
 #ifdef Q_WS_X11
 static char *x11_display = NULL;
 #endif
+static vlc_mutex_t lock = VLC_STATIC_MUTEX;
 
 /*****************************************************************************
  * Module callbacks
@@ -293,6 +294,12 @@ static int Open( vlc_object_t *p_this, bool isDialogProvider )
     putenv( (char *)"XLIB_SKIP_ARGB_VISUALS=1" );
 #endif
 
+    if (vlc_mutex_trylock (&lock))
+    {
+        msg_Err (p_this, "cannot start Qt4 multiple times");
+        return VLC_EGENERIC;
+    }
+
     /* Allocations of p_sys */
     intf_sys_t *p_sys = p_intf->p_sys = new intf_sys_t;
     p_intf->p_sys->b_isDialogProvider = isDialogProvider;
@@ -305,6 +312,7 @@ 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);
         return VLC_ENOMEM;
     }
 
@@ -346,6 +354,7 @@ static void Close( vlc_object_t *p_this )
 
     vlc_join (p_sys->thread, NULL);
     delete p_sys;
+    vlc_mutex_unlock (&lock);
 #ifdef Q_WS_X11
     free (x11_display);
 #endif




More information about the vlc-devel mailing list