]> git.sesse.net Git - vlc/blobdiff - modules/gui/minimal_macosx/intf.m
macosx: run on first thread directly, like already done by Qt4
[vlc] / modules / gui / minimal_macosx / intf.m
index 340f1955f851f39b20490140b4f6a94012dafea0..e31ebb91b263200f232ea1c81f36d09d64abc837 100644 (file)
@@ -7,13 +7,13 @@
  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
  *          Christophe Massiot <massiot@via.ecp.fr>
  *          Derk-Jan Hartman <hartman at videolan.org>
- *          Felix K\9fhne <fkuehne at videolan dot org>
+ *          Felix KΓΌhne <fkuehne at videolan dot org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 #include <stdlib.h>                                      /* malloc(), free() */
 #include <sys/param.h>                                    /* for MAXPATHLEN */
 #include <string.h>
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
 
 #include <vlc_keys.h>
 
 #include <vlc_input.h>
+#import <vlc_interface.h>
+#include "../../../lib/libvlc_internal.h"
 
 #import <intf.h>
 
@@ -46,19 +52,20 @@ static void Run ( intf_thread_t *p_intf );
 /*****************************************************************************
  * OpenIntf: initialize interface
  *****************************************************************************/
-int E_(OpenIntf) ( vlc_object_t *p_this )
+int OpenIntf ( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t*) p_this;
 
     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
     if( p_intf->p_sys == NULL )
     {
-        return( 1 );
+        return VLC_ENOMEM;
     }
 
     memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
 
-    p_intf->pf_run = Run;
+    libvlc_SetExitHandler( p_intf->p_libvlc, vlc_object_kill, p_intf );
+    Run( p_intf );
 
     return VLC_SUCCESS;
 }
@@ -66,7 +73,7 @@ int E_(OpenIntf) ( vlc_object_t *p_this )
 /*****************************************************************************
  * CloseIntf: destroy interface
  *****************************************************************************/
-void E_(CloseIntf) ( vlc_object_t *p_this )
+void CloseIntf ( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t*) p_this;
 
@@ -84,6 +91,34 @@ extern OSErr    CPSGetCurrentProcess( CPSProcessSerNum *psn);
 extern OSErr    CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
 extern OSErr    CPSSetFrontProcess( CPSProcessSerNum *psn);
 
+/*****************************************************************************
+ * KillerThread: Thread that kill the application
+ *****************************************************************************/
+static void * KillerThread( void *user_data )
+{
+    NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
+
+    intf_thread_t *p_intf = user_data;
+
+    vlc_mutex_init( &p_intf->p_sys->lock );
+    vlc_cond_init( &p_intf->p_sys->wait );
+
+    vlc_mutex_lock ( &p_intf->p_sys->lock );
+    while( vlc_object_alive( p_intf ) )
+        vlc_cond_wait( &p_intf->p_sys->wait, &p_intf->p_sys->lock );
+    vlc_mutex_unlock( &p_intf->p_sys->lock );
+
+    vlc_mutex_destroy( &p_intf->p_sys->lock );
+    vlc_cond_destroy( &p_intf->p_sys->wait );
+
+    msg_Dbg( p_intf, "Killing the Minimal Mac OS X module" );
+
+    /* We are dead, terminate */
+    [NSApp terminate: nil];
+    [o_pool release];
+    return NULL;
+}
+
 /*****************************************************************************
  * Run: main loop
  *****************************************************************************/
@@ -91,11 +126,6 @@ static void Run( intf_thread_t *p_intf )
 {
     sigset_t set;
 
-    /* Do it again - for some unknown reason, vlc_thread_create() often
-     * fails to go to real-time priority with the first launched thread
-     * (???) --Meuuh */
-    vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
-
     /* Make sure the "force quit" menu item does quit instantly.
      * VLC overrides SIGTERM which is sent by the "force quit"
      * menu item to make sure deamon mode quits gracefully, so
@@ -103,6 +133,11 @@ static void Run( intf_thread_t *p_intf )
     sigemptyset( &set );
     sigaddset( &set, SIGTERM );
     pthread_sigmask( SIG_UNBLOCK, &set, NULL );
+
+    /* Setup a thread that will monitor the module killing */
+    pthread_t killer_thread;
+    pthread_create( &killer_thread, NULL, KillerThread, p_intf );
+
     CPSProcessSerNum PSN;
     NSAutoreleasePool   *pool = [[NSAutoreleasePool alloc] init];
     [NSApplication sharedApplication];
@@ -111,6 +146,9 @@ static void Run( intf_thread_t *p_intf )
             if (!CPSSetFrontProcess(&PSN))
                 [NSApplication sharedApplication];
     [NSApp run];
+
+    pthread_join( killer_thread, NULL );
+
     [pool release];
 }