[vlc-devel] [PATCH 5/5] addons: Make fetcher & installer threads interruptible
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Thu Nov 2 14:35:31 CET 2017
---
src/misc/addons.c | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/src/misc/addons.c b/src/misc/addons.c
index 662b6bcc79..94ebba2ae8 100644
--- a/src/misc/addons.c
+++ b/src/misc/addons.c
@@ -26,6 +26,7 @@
#include <vlc_atomic.h>
#include <vlc_modules.h>
#include <vlc_arrays.h>
+#include <vlc_interrupt.h>
#include "libvlc.h"
#include <vlc_addons.h>
@@ -50,6 +51,7 @@ struct addons_manager_private_t
vlc_cond_t waitcond;
bool b_live;
vlc_mutex_t lock;
+ vlc_interrupt_t *p_interrupt;
DECL_ARRAY(char*) uris;
DECL_ARRAY(addon_entry_t*) entries;
} finder;
@@ -60,6 +62,7 @@ struct addons_manager_private_t
vlc_cond_t waitcond;
bool b_live;
vlc_mutex_t lock;
+ vlc_interrupt_t *p_interrupt;
DECL_ARRAY(addon_entry_t*) entries;
} installer;
};
@@ -140,6 +143,20 @@ addons_manager_t *addons_manager_New( vlc_object_t *p_this,
p_manager->owner = *owner;
p_manager->p_priv->p_parent = p_this;
+ p_manager->p_priv->finder.p_interrupt = vlc_interrupt_create();
+ p_manager->p_priv->installer.p_interrupt = vlc_interrupt_create();
+ if ( !p_manager->p_priv->finder.p_interrupt ||
+ !p_manager->p_priv->installer.p_interrupt )
+ {
+ if( p_manager->p_priv->finder.p_interrupt )
+ vlc_interrupt_destroy( p_manager->p_priv->finder.p_interrupt );
+ if( p_manager->p_priv->installer.p_interrupt )
+ vlc_interrupt_destroy( p_manager->p_priv->installer.p_interrupt );
+ free( p_manager->p_priv );
+ free( p_manager );
+ return NULL;
+ }
+
#define INIT_QUEUE( name ) \
p_manager->p_priv->name.b_live = false;\
vlc_mutex_init( &p_manager->p_priv->name.lock );\
@@ -162,6 +179,7 @@ void addons_manager_Delete( addons_manager_t *p_manager )
vlc_mutex_unlock( &p_manager->p_priv->finder.lock );
if ( b_live )
{
+ vlc_interrupt_kill( p_manager->p_priv->finder.p_interrupt );
vlc_cancel( p_manager->p_priv->finder.thread );
vlc_join( p_manager->p_priv->finder.thread, NULL );
}
@@ -171,6 +189,7 @@ void addons_manager_Delete( addons_manager_t *p_manager )
vlc_mutex_unlock( &p_manager->p_priv->installer.lock );
if ( b_live )
{
+ vlc_interrupt_kill( p_manager->p_priv->installer.p_interrupt );
vlc_cancel( p_manager->p_priv->installer.thread );
vlc_join( p_manager->p_priv->installer.thread, NULL );
}
@@ -181,7 +200,8 @@ void addons_manager_Delete( addons_manager_t *p_manager )
FOREACH_END();\
ARRAY_RESET( p_manager->p_priv->name.entries );\
vlc_mutex_destroy( &p_manager->p_priv->name.lock );\
- vlc_cond_destroy( &p_manager->p_priv->name.waitcond );
+ vlc_cond_destroy( &p_manager->p_priv->name.waitcond );\
+ vlc_interrupt_destroy( p_manager->p_priv->name.p_interrupt );
FREE_QUEUE( finder )
FREE_QUEUE( installer )
@@ -302,6 +322,7 @@ static void LoadLocalStorage( addons_manager_t *p_manager )
static void *FinderThread( void *p_data )
{
addons_manager_t *p_manager = p_data;
+ vlc_interrupt_set( p_manager->p_priv->finder.p_interrupt );
for( ;; )
{
@@ -414,6 +435,7 @@ static int installOrRemoveAddon( addons_manager_t *p_manager, addon_entry_t *p_e
static void *InstallerThread( void *p_data )
{
addons_manager_t *p_manager = p_data;
+ vlc_interrupt_set( p_manager->p_priv->installer.p_interrupt );
int i_ret;
for( ;; )
--
2.11.0
More information about the vlc-devel
mailing list