[vlc-devel] commit: Win32: correct the 'one-instance' deallocation code (Erwan Tulou )

git version control git at videolan.org
Wed Jan 27 23:21:53 CET 2010


vlc | branch: master | Erwan Tulou <erwan10 at videolan.org> | Wed Jan 27 23:08:38 2010 +0100| [1441dee2edebf99e6acb64450418389b8a7bba4c] | committer: Erwan Tulou 

Win32: correct the 'one-instance' deallocation code

'one-instance' happens to work on Win32 though there are several issues:
- a WM_QUIT is sent to the helper thread when any instance terminates
 (the master or a secondary instance). 'one-instance' should then stop
 working as soon as the first secondary instance terminates.
- But, sending WM_QUIT via SendMessage directly calls the window
procedure callback. And this callback here doesn't process the message
at all. Therefore, it is a no-op and the thread is actually never stopped.

This patch does the following :
- move the WM_QUIT message to ensure that only the master (first) instance
 stops the helper thread.
- process the WM_QUIT message in the window procedure callback, and call
for clean termination of the thread.

Note that PostQuitMessage cannot be directly called as there are two
distincts threads here.

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

 src/win32/specific.c |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/win32/specific.c b/src/win32/specific.c
index bf131fb..9300140 100644
--- a/src/win32/specific.c
+++ b/src/win32/specific.c
@@ -310,7 +310,11 @@ static unsigned __stdcall IPCHelperThread( void *data )
 LRESULT CALLBACK WMCOPYWNDPROC( HWND hwnd, UINT uMsg, WPARAM wParam,
                                 LPARAM lParam )
 {
-    if( uMsg == WM_COPYDATA )
+    if( uMsg == WM_QUIT  )
+    {
+        PostQuitMessage( 0 );
+    }
+    else if( uMsg == WM_COPYDATA )
     {
         COPYDATASTRUCT *pwm_data = (COPYDATASTRUCT*)lParam;
         vlc_object_t *p_this;
@@ -382,13 +386,16 @@ void system_End( libvlc_int_t *p_this )
         psz_vlcpath = NULL;
     }
 
-    if( ( ipcwindow = FindWindow( 0, L"VLC ipc "VERSION ) ) != 0 )
-    {
-        SendMessage( ipcwindow, WM_QUIT, 0, 0 );
-    }
-
     if (p_helper && p_helper->p_parent == VLC_OBJECT(p_this) )
     {
+        /* this is the first instance (in a one-instance system)
+         * it is the owner of the helper thread
+         */
+        if( ( ipcwindow = FindWindow( 0, L"VLC ipc "VERSION ) ) != 0 )
+        {
+            SendMessage( ipcwindow, WM_QUIT, 0, 0 );
+        }
+
         /* FIXME: thread-safety... */
         vlc_object_detach (p_helper);
         vlc_object_release (p_helper);




More information about the vlc-devel mailing list