]> git.sesse.net Git - vlc/commitdiff
* Get rid of the Manager thread by making blocking interfaces listen to
authorClément Stenac <zorglub@videolan.org>
Sun, 24 Sep 2006 09:34:57 +0000 (09:34 +0000)
committerClément Stenac <zorglub@videolan.org>
Sun, 24 Sep 2006 09:34:57 +0000 (09:34 +0000)
  p_libvlc->b_die
  Not implemented for OS X as I am not sure, please check if it is feasible.
* Don't run the dummy interface

21 files changed:
include/vlc_interface.h
modules/control/corba/corba.c
modules/control/gestures.c
modules/control/hotkeys.c
modules/control/http/http.c
modules/control/lirc.c
modules/control/motion.c
modules/control/netsync.c
modules/control/rc.c
modules/control/showintf.c
modules/control/telnet.c
modules/gui/beos/Interface.cpp
modules/gui/macosx/intf.m
modules/gui/ncurses.c
modules/gui/pda/pda.c
modules/gui/qt4/main_interface.cpp
modules/gui/skins2/src/vlcproc.cpp
modules/gui/wince/timer.cpp
modules/gui/wxwidgets/timer.cpp
modules/misc/dummy/interface.c
src/interface/interface.c

index 5b127089fde7c06703917f35aa4d177247560e69..b01d2356f43e701cdfdd8ae657b1a46133806204 100644 (file)
@@ -119,6 +119,10 @@ VLC_EXPORT( int,               intf_RunThread,  ( intf_thread_t * ) );
 VLC_EXPORT( void,              intf_StopThread, ( intf_thread_t * ) );
 VLC_EXPORT( void,              intf_Destroy,    ( intf_thread_t * ) );
 
+/* If the interface is in the main thread, it should listen both to
+ * p_intf->b_die and p_libvlc->b_die */
+#define intf_ShouldDie( p_intf ) (p_intf->b_die || (p_intf->b_block && p_intf->p_libvlc->b_die ) )
+
 /*@}*/
 
 /*****************************************************************************
index 604ff3f78fb98cd87b0681252afba574cde4232a..bc063c8e38053c25dfc6e82d2526fc07231b03b9 100644 (file)
@@ -757,13 +757,13 @@ static gboolean Manage( gpointer p_interface )
         msg_Err( p_intf, "Exception in CORBA events check loop" );
         return FALSE;
     }
-  
+
     vlc_mutex_lock( &p_intf->change_lock );
 
     if( b_work_pending )
         CORBA_ORB_perform_work( p_intf->p_sys->orb, ev );
-  
-    if( p_intf->b_die )
+
+    if( intf_ShouldDie( p_intf ) )
     {
         vlc_mutex_unlock( &p_intf->change_lock );
         CORBA_ORB_shutdown( p_intf->p_sys->orb, TRUE, ev );
index 16de437ce91869aea498ec35384c0ce1b3ab1f42..627e1bb1a56907be2783e2c69909304599f50a05 100644 (file)
@@ -155,7 +155,7 @@ static void RunIntf( intf_thread_t *p_intf )
     msg_Dbg( p_intf, "interface thread initialized" );
 
     /* Main loop */
-    while( !p_intf->b_die )
+    while( !intf_ShouldDie( p_intf ) )
     {
         vlc_mutex_lock( &p_intf->change_lock );
 
@@ -261,7 +261,7 @@ static int InitThread( intf_thread_t * p_intf )
 {
     char *psz_button;
     /* we might need some locking here */
-    if( !p_intf->b_die )
+    if( !intf_ShouldDie( p_intf ) )
     {
         input_thread_t * p_input;
 
index fd6c118990e5326faff52b1b3fd7e1ab9f4f40a1..fe0c9b6dc5192e59377e7f1540827cf96f6d6c77 100644 (file)
@@ -164,7 +164,7 @@ static void Run( intf_thread_t *p_intf )
         var_Set( p_intf->p_libvlc, p_hotkeys[i].psz_action, val );
     }
 
-    while( !p_intf->b_die )
+    while( !intf_ShouldDie( p_intf ) )
     {
         int i_key, i_action;
         int i_times = 0;
index d8ea465450959641ed3d3a9351fa27d7b1357f94..094f9f4d5ca63741ce9dee688ef90c903db77cb2 100644 (file)
@@ -431,7 +431,7 @@ static void Run( intf_thread_t *p_intf )
 {
     intf_sys_t     *p_sys = p_intf->p_sys;
 
-    while( !p_intf->b_die )
+    while( !intf_ShouldDie( p_intf ) )
     {
         /* get the playlist */
         if( p_sys->p_playlist == NULL )
index 3e2e71cc63551e7a15755c2aec8cbc96a4f4757f..fae7fabc31789d50b947a5a96159051bc78afa32 100644 (file)
@@ -120,7 +120,7 @@ static void Run( intf_thread_t *p_intf )
 {
     char *code, *c;
 
-    while( !p_intf->b_die )
+    while( !intf_ShouldDie( p_intf ) )
     {
         /* Sleep a bit */
         msleep( INTF_IDLE_SLEEP );
@@ -136,7 +136,7 @@ static void Run( intf_thread_t *p_intf )
             continue;
         }
 
-        while( !p_intf->b_die
+        while( !intf_ShouldDie( p_intf )
                 && lirc_code2char( p_intf->p_sys->config, code, &c ) == 0
                 && c != NULL )
         {
index d723b936d358ffe275a3d84762bb93d75249296b..25856e6b1cbda6f93531573511fd631a1a5b3c39 100644 (file)
@@ -132,7 +132,7 @@ static void RunIntf( intf_thread_t *p_intf )
 {
     int i_x, i_oldx = 0;
 
-    while( !p_intf->b_die )
+    while( !intf_ShouldDie( p_intf ) )
     {
 #define LOW_THRESHOLD 80
 #define HIGH_THRESHOLD 100
index 5280814a4f535825f865264dcba2b0ad3cc0294c..fbe56124f25e8bc2351717a81ea10b64aec4d783 100644 (file)
@@ -159,7 +159,7 @@ static void Run( intf_thread_t *p_intf )
     /* High priority thread */
     vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_INPUT );
 
-    while( !p_intf->b_die )
+    while( !intf_ShouldDie( p_intf ) )
     {
         struct timeval timeout;
         fd_set fds_r;
index 49b5d44f4fb32a2446f3b11324a9251e3f486418..7587a1b8bc549630319e36333723963d0c8933fa 100644 (file)
@@ -560,7 +560,7 @@ static void Run( intf_thread_t *p_intf )
     }
 #endif
 
-    while( !p_intf->b_die )
+    while( !intf_ShouldDie( p_intf ) )
     {
         char *psz_cmd, *psz_arg;
         vlc_bool_t b_complete;
@@ -2201,7 +2201,7 @@ vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
     while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
                                 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
     {
-        while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
+        while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
                ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
                                  1, &i_dw ) )
         {
@@ -2271,7 +2271,7 @@ vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
     }
 #endif
 
-    while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
+    while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
            (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
                        0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
                   (uint8_t *)p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
index 55cc2713fa9ff584dfa429fd7f907ec620470f46..801987e90f2e07bfbe506438a18467d9411b590f 100644 (file)
@@ -116,7 +116,7 @@ static void RunIntf( intf_thread_t *p_intf )
     }
 
     /* Main loop */
-    while( !p_intf->b_die )
+    while( !intf_ShouldDie( p_intf ) )
     {
         vlc_mutex_lock( &p_intf->change_lock );
 
@@ -175,7 +175,7 @@ static void RunIntf( intf_thread_t *p_intf )
  *****************************************************************************/
 static int InitThread( intf_thread_t * p_intf )
 {
-    if( !p_intf->b_die )
+    if( !intf_ShouldDie( p_intf ) )
     {
         vlc_mutex_lock( &p_intf->change_lock );
 
index 9bf7278b4058bacfb0b5590313b6cc6b37221146..2bf5c024b4ca748b203b25eef6a7448451014de2 100644 (file)
@@ -245,7 +245,7 @@ static void Run( intf_thread_t *p_intf )
 
     psz_password = config_GetPsz( p_intf, "telnet-password" );
 
-    while( !p_intf->b_die )
+    while( !intf_ShouldDie( p_intf ) )
     {
         fd_set fds_read, fds_write;
         int    i_handle_max = 0;
index 2b817ea882b7eafd491ef9ca08911d5eda3ecd2c..a480e9818bd16a22244732e7cbb8e025930cc381 100644 (file)
@@ -119,7 +119,7 @@ void E_(CloseIntf) ( vlc_object_t *p_this )
  *****************************************************************************/
 static void Run( intf_thread_t *p_intf )
 {
-    while( !p_intf->b_die )
+    while( !intf_ShouldDie( p_intf ) )
     {
         p_intf->p_sys->p_window->UpdateInterface();
         msleep( INTF_IDLE_SLEEP );
index e89796e2ec6b74eebcbfcc737f10152d99acaca6..4c8161f03939720e2b83295014ccc5dfba1cf319 100644 (file)
@@ -1006,7 +1006,7 @@ static VLCMain *_o_sharedMainInstance = nil;
 
     vlc_object_release( p_playlist );
 
-    while( !p_intf->b_die )
+    while( !intf_ShouldDie( p_intf ) )
     {
         vlc_mutex_lock( &p_intf->change_lock );
 
index a63d7ba31252fe1d47cef6eae29a75479a76cf57..0e7c541be293863616b4aa83e2b6def25bd3255f 100644 (file)
@@ -336,7 +336,7 @@ static void Run( intf_thread_t *p_intf )
      */
     t_last_refresh = ( time( 0 ) - 1);
 
-    while( !p_intf->b_die )
+    while( !intf_ShouldDie( p_intf ) )
     {
         msleep( INTF_IDLE_SLEEP );
 
index 0f5be409b378da59a2c17ca7318f3603d602fd54..ae9fac907eb1f5ea0a1d71777eac084f171404aa 100644 (file)
@@ -319,7 +319,7 @@ static void Run( intf_thread_t *p_intf )
 
 #ifdef NEED_GTK2_MAIN
     msg_Dbg( p_intf, "Manage GTK keyboard events using threads" );
-    while( !p_intf->b_die )
+    while( !intf_ShouldDie( p_intf ) )
     {
         Manage( p_intf );
 
@@ -518,14 +518,14 @@ static int Manage( intf_thread_t *p_intf )
         }
         vlc_mutex_unlock( &p_input->object_lock );
     }
-    else if( p_intf->p_sys->b_playing && !p_intf->b_die )
+    else if( p_intf->p_sys->b_playing && !intf_ShouldDie( p_intf ) )
     {
         E_(GtkModeManage)( p_intf );
         p_intf->p_sys->b_playing = 0;
     }
 
 #ifndef NEED_GTK2_MAIN
-    if( p_intf->b_die )
+    if( intf_ShouldDie( p_intf ) )
     {
         vlc_mutex_unlock( &p_intf->change_lock );
 
index f6238520c6fea7ecbc84202990205275fe3ad0a4..7251d2e59397f29651b516c955c5c1c4588f89a1 100644 (file)
@@ -621,7 +621,7 @@ void MainInterface::updateOnTimer()
     advControls->enableInput( THEMIM->getIM()->hasInput() );
     advControls->enableVideo( THEMIM->getIM()->hasVideo() );
 
-    if( p_intf->b_die )
+    if( intf_ShouldDie( p_intf ) )
     {
         QApplication::closeAllWindows();
         QApplication::quit();
index fc04626fc3cab29c7c3975b9c2e8e21ffb7b0281..608a41cad827ee2eaadc162e17e610fc50d0d503 100644 (file)
@@ -230,7 +230,7 @@ void VlcProc::dropVout()
 void VlcProc::manage()
 {
     // Did the user request to quit vlc ?
-    if( getIntf()->b_die || getIntf()->p_libvlc->b_die )
+    if( intf_ShouldDie( getIntf() ) )
     {
         CmdQuit *pCmd = new CmdQuit( getIntf() );
         AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
index a9a5c3a26980c7752d74fc64c981449e47719f2b..bcb887406288e9dbebb30e9fc727b8b26ed6cf68 100644 (file)
@@ -210,14 +210,14 @@ void Timer::Notify( void )
             }
         }
     }
-    else if( p_intf->p_sys->b_playing && !p_intf->b_die )
+    else if( p_intf->p_sys->b_playing && !intf_ShouldDie( p_intf ) )
     {
         p_intf->p_sys->b_playing = 0;
         p_main_interface->TogglePlayButton( PAUSE_S );
         i_old_playing_status = PAUSE_S;
     }
 
-    if( p_intf->b_die )
+    if( intf_ShouldDie( p_intf ) )
     {
         vlc_mutex_unlock( &p_intf->change_lock );
 
index 4ba69a621b8df9d2e745cb8db91e1266c2f394c2..9d77eccf30e5dea8a580b30d989fd8697668bb44 100644 (file)
@@ -107,7 +107,7 @@ void Timer::Notify()
         p_intf->p_sys->b_intf_show = VLC_FALSE;
     }
 
-    if( p_intf->b_die )
+    if( intf_ShouldDie( p_intf ) )
     {
         vlc_mutex_unlock( &p_intf->change_lock );
 
index 3b33c4f52f6529b52c8998a36cdf6e64cc515e1c..2366bd272ebc73a13c2eecd6960e55853b93b5a4 100644 (file)
@@ -51,20 +51,7 @@ int  E_(OpenIntf) ( vlc_object_t *p_this )
 
     msg_Info( p_intf, "using the dummy interface module..." );
 
-    p_intf->pf_run = Run;
+    p_intf->pf_run = NULL;
 
     return VLC_SUCCESS;
 }
-
-/*****************************************************************************
- * Run: main loop
- *****************************************************************************/
-static void Run( intf_thread_t *p_intf )
-{
-    while( !p_intf->b_die )
-    {
-        /* Wait a bit */
-        msleep( INTF_IDLE_SLEEP );
-    }
-}
-
index fbf9686f587a7ab25c5458006ada28e0dc7d4d4d..6216136fc5b521520815e30f779faffaa1d9552f 100644 (file)
@@ -52,7 +52,6 @@
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static void Manager( intf_thread_t *p_intf );
 static void RunInterface( intf_thread_t *p_intf );
 
 static int SwitchIntfCallback( vlc_object_t *, char const *,
@@ -61,6 +60,7 @@ static int AddIntfCallback( vlc_object_t *, char const *,
                             vlc_value_t , vlc_value_t , void * );
 
 #ifdef __APPLE__
+static void Manager( intf_thread_t *p_intf );
 /*****************************************************************************
  * VLCApplication interface
  *****************************************************************************/
@@ -188,9 +188,8 @@ int intf_RunThread( intf_thread_t *p_intf )
     {
         /* This interface doesn't need to be run */
         if( !p_intf->pf_run )
-        {
             return VLC_SUCCESS;
-        }
+
         /* Run the interface in a separate thread */
         if( !strcmp( p_intf->p_module->psz_object_name, "macosx" ) )
         {
@@ -216,16 +215,16 @@ int intf_RunThread( intf_thread_t *p_intf )
 #else
     if( p_intf->b_block )
     {
-        /* Run a manager thread, launch the interface, kill the manager */
-        if( vlc_thread_create( p_intf, "manager", Manager,
-                               VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
+        /* If the main interface does not have a run function,
+         * implement a waiting loop ourselves
+         */
+        if( p_intf->pf_run )
+            RunInterface( p_intf );
+        else
         {
-            msg_Err( p_intf, "cannot spawn manager thread" );
-            return VLC_EGENERIC;
+            while( !intf_ShouldDie( p_intf ) )
+                msleep( INTF_IDLE_SLEEP * 2);
         }
-
-        RunInterface( p_intf );
-
         p_intf->b_die = VLC_TRUE;
         /* Do not join the thread... intf_StopThread will do it for us */
     }
@@ -261,11 +260,9 @@ void intf_StopThread( intf_thread_t *p_intf )
     if( !p_intf->b_block )
     {
         p_intf->b_die = VLC_TRUE;
+        if( p_intf->pf_run )
+            vlc_thread_join( p_intf );
     }
-
-    /* Wait for the thread to exit */
-    if( p_intf->pf_run )
-        vlc_thread_join( p_intf );
 }
 
 /**
@@ -293,24 +290,9 @@ void intf_Destroy( intf_thread_t *p_intf )
 /* Following functions are local */
 
 /*****************************************************************************
- * Manager: helper thread for blocking interfaces
- *****************************************************************************
- * If the interface is launched in the main thread, it will not listen to
- * p_vlc->b_die events because it is only supposed to listen to p_intf->b_die.
- * This thread takes care of the matter.
+ * Manager: helper thread for blocking OS X
  *****************************************************************************/
-/**
- * \brief Helper thread for blocking interfaces.
- * \ingroup vlc_interface
- *
- * This is a local function
- * If the interface is launched in the main thread, it will not listen to
- * p_vlc->b_die events because it is only supposed to listen to p_intf->b_die.
- * This thread takes care of the matter.
- * \see intf_RunThread
- * \param p_intf an interface thread
- * \return nothing
- */
+#ifdef __APPLE__
 static void Manager( intf_thread_t *p_intf )
 {
     while( !p_intf->b_die )
@@ -320,16 +302,15 @@ static void Manager( intf_thread_t *p_intf )
         if( p_intf->p_libvlc->b_die )
         {
             p_intf->b_die = VLC_TRUE;
-#ifdef __APPLE__
-    if( strncmp( p_intf->p_libvlc->psz_object_name, "clivlc", 6 ) )
-    {
-        [NSApp stop: NULL];
-    }
-#endif
+            if( strncmp( p_intf->p_libvlc->psz_object_name, "clivlc", 6 ) )
+            {
+                [NSApp stop: NULL];
+            }
             return;
         }
     }
 }
+#endif
 
 /*****************************************************************************
  * RunInterface: setups necessary data and give control to the interface