Move the messages update function to another thread. It prevents it from
authorEric Petit <titer@videolan.org>
Mon, 10 Feb 2003 15:23:46 +0000 (15:23 +0000)
committerEric Petit <titer@videolan.org>
Mon, 10 Feb 2003 15:23:46 +0000 (15:23 +0000)
 freezing the main window (cannot seek anymore, etc).

modules/gui/beos/InterfaceWindow.cpp
modules/gui/beos/InterfaceWindow.h
modules/gui/beos/MessagesWindow.cpp
modules/gui/beos/MessagesWindow.h

index f522aa3..c0aa40f 100644 (file)
@@ -2,7 +2,7 @@
  * InterfaceWindow.cpp: beos interface
  *****************************************************************************
  * Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: InterfaceWindow.cpp,v 1.29 2003/02/09 17:10:52 stippi Exp $
+ * $Id: InterfaceWindow.cpp,v 1.30 2003/02/10 15:23:46 titer Exp $
  *
  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -791,11 +791,6 @@ void InterfaceWindow::UpdateInterface()
         }
     }
 
-       // strangly, someone is calling this function even after the object has been destructed!
-       // even more strangly, this workarround seems to work
-       if (fMessagesWindow)
-           fMessagesWindow->UpdateMessages();
-
     fLastUpdateTime = system_time();
 }
 
index 1d3793a..714f4af 100644 (file)
@@ -2,7 +2,7 @@
  * InterfaceWindow.h: BeOS interface window class prototype
  *****************************************************************************
  * Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: InterfaceWindow.h,v 1.12 2003/02/09 17:10:52 stippi Exp $
+ * $Id: InterfaceWindow.h,v 1.13 2003/02/10 15:23:46 titer Exp $
  *
  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
  *          Tony Castley <tcastley@mail.powerup.com.au>
@@ -106,6 +106,7 @@ class InterfaceWindow : public BWindow
             bool            IsStopped() const;
         
     MediaControlView*        p_mediaControl;
+    MessagesWindow*         fMessagesWindow;
 
  private:    
             void            _UpdatePlaylist();
@@ -126,7 +127,6 @@ class InterfaceWindow : public BWindow
     BFilePanel*             fFilePanel;
     PlayListWindow*         fPlaylistWindow;
     PreferencesWindow*      fPreferencesWindow;
-    MessagesWindow*         fMessagesWindow;
     BMenuBar*               fMenuBar;
     BMenuItem*                         fGotoMenuMI;
     BMenuItem*              fNextTitleMI;
index af9d8be..8200927 100644 (file)
@@ -2,7 +2,7 @@
  * MessagesWindow.cpp: beos interface
  *****************************************************************************
  * Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: MessagesWindow.cpp,v 1.6 2003/02/01 12:01:11 stippi Exp $
+ * $Id: MessagesWindow.cpp,v 1.7 2003/02/10 15:23:46 titer Exp $
  *
  * Authors: Eric Petit <titer@videolan.org>
  *
 
 /* BeOS module headers */
 #include "VlcWrapper.h"
+#include "InterfaceWindow.h"
 #include "MessagesWindow.h"
 
+static int UpdateMessages( intf_thread_t * p_intf );
+
 /*****************************************************************************
  * MessagesWindow::MessagesWindow
  *****************************************************************************/
@@ -42,7 +45,6 @@ MessagesWindow::MessagesWindow( intf_thread_t * p_intf,
                B_NOT_ZOOMABLE )
 {
        this->p_intf = p_intf;
-       p_sub = p_intf->p_sys->p_sub;
        
        BRect rect, textRect;
        
@@ -62,6 +64,13 @@ MessagesWindow::MessagesWindow( intf_thread_t * p_intf,
     /* start window thread in hidden state */
     Hide();
     Show();
+
+    /* update it */
+    if( vlc_thread_create( p_intf, "update messages", UpdateMessages,
+                           VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
+    {
+        msg_Err( p_intf, "cannot create update messages thread" );
+    }
 }
 
 /*****************************************************************************
@@ -69,6 +78,7 @@ MessagesWindow::MessagesWindow( intf_thread_t * p_intf,
  *****************************************************************************/
 MessagesWindow::~MessagesWindow()
 {
+    vlc_thread_join( p_intf );
 }
 
 /*****************************************************************************
@@ -101,78 +111,93 @@ void MessagesWindow::ReallyQuit()
 }
 
 /*****************************************************************************
- * MessagesWindow::UpdateMessages
+ * UpdateMessages
  *****************************************************************************/
-void MessagesWindow::UpdateMessages()
+static int UpdateMessages( intf_thread_t * p_intf )
 {
-    int i_start, oldLength;
-    char * psz_module_type = NULL;
-    rgb_color red = { 200, 0, 0 };
-    rgb_color gray = { 150, 150, 150 };
-    rgb_color green = { 0, 150, 0 };
-    rgb_color orange = { 230, 180, 00 };
-    rgb_color color;
-    
-    vlc_mutex_lock( p_sub->p_lock );
-    int i_stop = *p_sub->pi_stop;
-    vlc_mutex_unlock( p_sub->p_lock );
+    /* workaround: wait a bit or it'll crash */
+    msleep( 500000 );
+
+    intf_sys_t * p_sys = (intf_sys_t*)p_intf->p_sys;
+    msg_subscription_t * p_sub = p_sys->p_sub;
+    MessagesWindow * messagesWindow = p_sys->p_window->fMessagesWindow;
+    BTextView * messagesView = messagesWindow->fMessagesView;
+    BScrollBar * scrollBar = messagesWindow->fScrollBar;
 
-    if( p_sub->i_start != i_stop )
+    while( !p_intf->b_die )
     {
-        for( i_start = p_sub->i_start;
-             i_start != i_stop;
-             i_start = (i_start+1) % VLC_MSG_QSIZE )
+        int i_start, oldLength;
+        char * psz_module_type = NULL;
+        rgb_color red = { 200, 0, 0 };
+        rgb_color gray = { 150, 150, 150 };
+        rgb_color green = { 0, 150, 0 };
+        rgb_color orange = { 230, 180, 00 };
+        rgb_color color;
+    
+        vlc_mutex_lock( p_sub->p_lock );
+        int i_stop = *p_sub->pi_stop;
+        vlc_mutex_unlock( p_sub->p_lock );
+
+        if( p_sub->i_start != i_stop )
         {
-            /* Add message */
-            switch( p_sub->p_msg[i_start].i_type )
+            for( i_start = p_sub->i_start;
+                 i_start != i_stop;
+                 i_start = (i_start+1) % VLC_MSG_QSIZE )
             {
-                case VLC_MSG_INFO: color = green; break;
-                case VLC_MSG_WARN: color = orange; break;
-                case VLC_MSG_ERR: color = red; break;
-                case VLC_MSG_DBG: color = gray; break;
-            }
+                /* Add message */
+                switch( p_sub->p_msg[i_start].i_type )
+                {
+                    case VLC_MSG_INFO: color = green; break;
+                    case VLC_MSG_WARN: color = orange; break;
+                    case VLC_MSG_ERR: color = red; break;
+                    case VLC_MSG_DBG: color = gray; break;
+                }
             
-            switch( p_sub->p_msg[i_start].i_object_type )
-            {
-                case VLC_OBJECT_ROOT: psz_module_type = "root"; break;
-                case VLC_OBJECT_VLC: psz_module_type = "vlc"; break;
-                case VLC_OBJECT_MODULE: psz_module_type = "module"; break;
-                case VLC_OBJECT_INTF: psz_module_type = "interface"; break;
-                case VLC_OBJECT_PLAYLIST: psz_module_type = "playlist"; break;
-                case VLC_OBJECT_ITEM: psz_module_type = "item"; break;
-                case VLC_OBJECT_INPUT: psz_module_type = "input"; break;
-                case VLC_OBJECT_DECODER: psz_module_type = "decoder"; break;
-                case VLC_OBJECT_VOUT: psz_module_type = "video output"; break;
-                case VLC_OBJECT_AOUT: psz_module_type = "audio output"; break;
-                case VLC_OBJECT_SOUT: psz_module_type = "stream output"; break;
-            }
-            
-            if ( fMessagesView->LockLooper() )
-            {
-                   oldLength = fMessagesView->TextLength();
-                   BString string;
-                   string << p_sub->p_msg[i_start].psz_module << " " << psz_module_type << " : " <<
-                       p_sub->p_msg[i_start].psz_msg << "\n";
-                   fMessagesView->Insert( string.String() );
-                   fMessagesView->SetFontAndColor( oldLength,
-                                                   fMessagesView->TextLength(),
-                                                   NULL, 0, &color );
-                   fMessagesView->Draw( fMessagesView->Bounds() );
-                   fMessagesView->UnlockLooper();
-            }
+                switch( p_sub->p_msg[i_start].i_object_type )
+                {
+                    case VLC_OBJECT_ROOT: psz_module_type = "root"; break;
+                    case VLC_OBJECT_VLC: psz_module_type = "vlc"; break;
+                    case VLC_OBJECT_MODULE: psz_module_type = "module"; break;
+                    case VLC_OBJECT_INTF: psz_module_type = "interface"; break;
+                    case VLC_OBJECT_PLAYLIST: psz_module_type = "playlist"; break;
+                    case VLC_OBJECT_ITEM: psz_module_type = "item"; break;
+                    case VLC_OBJECT_INPUT: psz_module_type = "input"; break;
+                    case VLC_OBJECT_DECODER: psz_module_type = "decoder"; break;
+                    case VLC_OBJECT_VOUT: psz_module_type = "video output"; break;
+                    case VLC_OBJECT_AOUT: psz_module_type = "audio output"; break;
+                    case VLC_OBJECT_SOUT: psz_module_type = "stream output"; break;
+                }
+   
+                if ( messagesView->LockLooper() )
+                {
+                   oldLength = messagesView->TextLength();
+                   BString string;
+                   string << p_sub->p_msg[i_start].psz_module << " " << psz_module_type << " : " <<
+                       p_sub->p_msg[i_start].psz_msg << "\n";
+                   messagesView->Insert( string.String() );
+                   messagesView->SetFontAndColor( oldLength,
+                                                  messagesView->TextLength(),
+                                                  NULL, 0, &color );
+                   messagesView->Draw( messagesView->Bounds() );
+                       messagesView->UnlockLooper();
+                }
             
-            /* Scroll at the end */
-            if( fScrollBar->LockLooper() )
-            {
-                float min, max;
-                fScrollBar->GetRange( &min, &max );
-                fScrollBar->SetValue( max );
-                fScrollBar->UnlockLooper();
+                /* Scroll at the end */
+                if( scrollBar->LockLooper() )
+                {
+                    float min, max;
+                    scrollBar->GetRange( &min, &max );
+                    scrollBar->SetValue( max );
+                    scrollBar->UnlockLooper();
+                }
             }
-        }
 
-        vlc_mutex_lock( p_sub->p_lock );
-        p_sub->i_start = i_start;
-        vlc_mutex_unlock( p_sub->p_lock );
+            vlc_mutex_lock( p_sub->p_lock );
+            p_sub->i_start = i_start;
+            vlc_mutex_unlock( p_sub->p_lock );
+        }
+        /* Wait a bit */
+        msleep( INTF_IDLE_SLEEP );
     }
+    return 0;
 }
index e74c23a..34a6696 100644 (file)
@@ -2,7 +2,7 @@
  * MessagesWindow.h
  *****************************************************************************
  * Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: MessagesWindow.h,v 1.2 2003/01/26 08:28:20 titer Exp $
+ * $Id: MessagesWindow.h,v 1.3 2003/02/10 15:23:46 titer Exp $
  *
  * Authors: Eric Petit <titer@videolan.org>
  *
@@ -36,11 +36,8 @@ class MessagesWindow : public BWindow
         virtual bool         QuitRequested();
         
         void                 ReallyQuit();
-        void                 UpdateMessages();
 
-    private:
         intf_thread_t *      p_intf;
-        msg_subscription_t * p_sub;
         
         BView *              fBackgroundView;
         BTextView *          fMessagesView;