]> git.sesse.net Git - vlc/commitdiff
libvlc_InternalWait, libvlc_Quit: wait and signal libvlc exit
authorRémi Denis-Courmont <rdenis@simphalempin.com>
Sat, 24 Jan 2009 18:21:57 +0000 (20:21 +0200)
committerRémi Denis-Courmont <rdenis@simphalempin.com>
Sat, 24 Jan 2009 18:57:47 +0000 (20:57 +0200)
include/vlc_interface.h
src/control/libvlc_internal.h
src/libvlc.c
src/libvlc.h
src/libvlccore.sym

index 056167a5480b4daf511ccef642ede25b4706827a..ee09b2d905682851fa5f20afa36b3feeddd8d0e4 100644 (file)
@@ -106,6 +106,8 @@ VLC_EXPORT( void,              intf_StopThread, ( intf_thread_t * ) );
 #define intf_Eject(a,b) __intf_Eject(VLC_OBJECT(a),b)
 VLC_EXPORT( int, __intf_Eject, ( vlc_object_t *, const char * ) );
 
+VLC_EXPORT( void, libvlc_Quit, ( libvlc_int_t * ) );
+
 VLC_EXPORT( int, interaction_Register, ( intf_thread_t * ) );
 VLC_EXPORT( int, interaction_Unregister, ( intf_thread_t * ) );
 
index a7520d28be833acd1b285bff91cb5081bf367fb6..2fcc51b9398420988cfc2984e92d8a853017c788 100644 (file)
@@ -45,6 +45,7 @@ VLC_EXPORT (void, libvlc_InternalCleanup, ( libvlc_int_t * ) );
 VLC_EXPORT (void, libvlc_InternalDestroy, ( libvlc_int_t * ) );
 
 VLC_EXPORT (int, libvlc_InternalAddIntf, ( libvlc_int_t *, const char * ) );
+VLC_EXPORT (void, libvlc_InternalWait, ( libvlc_int_t * ) );
 
 /***************************************************************************
  * Opaque structures for libvlc API
index 0114be64ef47a8e511d21ef84e3c8fa0adbc2c6e..ecfd6f0bd6b026a0f9c8b83ba1ed341091b53a13 100644 (file)
@@ -283,6 +283,7 @@ libvlc_int_t * libvlc_InternalCreate( void )
     /* Initialize mutexes */
     vlc_mutex_init( &priv->timer_lock );
     vlc_mutex_init( &priv->config_lock );
+    vlc_cond_init( &priv->exiting );
 
     return p_libvlc;
 }
@@ -1135,6 +1136,7 @@ void libvlc_InternalDestroy( libvlc_int_t *p_libvlc )
     msg_Destroy( p_libvlc );
 
     /* Destroy mutexes */
+    vlc_cond_destroy( &priv->exiting );
     vlc_mutex_destroy( &priv->config_lock );
     vlc_mutex_destroy( &priv->timer_lock );
 
@@ -1190,6 +1192,33 @@ int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, char const *psz_module )
     return VLC_SUCCESS;
 };
 
+/**
+ * Waits until the LibVLC instance gets an exit signal. Normally, this happens
+ * when the user "exits" an interface plugin.
+ */
+void libvlc_InternalWait( libvlc_int_t *p_libvlc )
+{
+    libvlc_priv_t *priv = libvlc_priv( p_libvlc );
+    vlc_object_internals_t *internals = vlc_internals( p_libvlc );
+
+    vlc_object_lock( p_libvlc );
+    while( vlc_object_alive( p_libvlc ) )
+        vlc_cond_wait( &priv->exiting, &internals->lock );
+    vlc_object_unlock( p_libvlc );
+}
+
+/**
+ * Posts an exit signal to LibVLC instance. This will normally initiate the
+ * cleanup and destroy process. It should only be called on behalf of the user.
+ */
+void libvlc_Quit( libvlc_int_t *p_libvlc )
+{
+    libvlc_priv_t *priv = libvlc_priv( p_libvlc );
+
+    vlc_object_kill( p_libvlc );
+    vlc_cond_signal( &priv->exiting ); /* OK, kill took care of the lock */
+}
+
 #if defined( ENABLE_NLS ) && (defined (__APPLE__) || defined (WIN32)) && \
     ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
 /*****************************************************************************
index a9c74d39ce1c959686e4c47c8e4f0e758a3e3457..c9330e9b20d67e2f38c2ff34001a3935f2525361 100644 (file)
@@ -198,6 +198,7 @@ typedef struct sap_handler_t sap_handler_t;
 typedef struct libvlc_priv_t
 {
     libvlc_int_t       public_data;
+    vlc_cond_t         exiting; ///< signaled when VLC wants to exit
 
     /* Configuration */
     vlc_mutex_t        config_lock; ///< config file lock
index f8275b99190a0aa6031688c7378e998a969aed62..a6ed45edb6b23e5ee4d7ba6c408c8d1ddf963cf2 100644 (file)
@@ -208,6 +208,8 @@ libvlc_InternalCleanup
 libvlc_InternalCreate
 libvlc_InternalDestroy
 libvlc_InternalInit
+libvlc_InternalWait
+libvlc_Quit
 LocaleFree
 mdate
 module_config_free