[vlc-devel] [RFC PATCH] access/live555: make sure timeout-thread is killed during close
Filip Roséen
filip at atch.se
Thu Aug 4 17:10:32 CEST 2016
Given that "msleep" is not a point-of-cancelation on a number of
different platforms (including android), this patch makes sure that we
can properly abort the spawned timeout-thread (if any) by making use of
an interrupt context.
vlc_msleep_i11e is used instead of msleep since it properly respects
the interrupt-context if such is present for the given thread.
---
modules/access/live555.cpp | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/modules/access/live555.cpp b/modules/access/live555.cpp
index 12c505a..cc8b929 100644
--- a/modules/access/live555.cpp
+++ b/modules/access/live555.cpp
@@ -177,6 +177,7 @@ struct timeout_thread_t
{
demux_t *p_demux;
vlc_thread_t handle;
+ vlc_interrupt_t* interrupt;
bool b_handle_keep_alive;
};
@@ -426,7 +427,9 @@ static void Close( vlc_object_t *p_this )
if( p_sys->p_timeout )
{
vlc_cancel( p_sys->p_timeout->handle );
+ vlc_interrupt_kill( p_sys->p_timeout->interrupt );
vlc_join( p_sys->p_timeout->handle, NULL );
+ vlc_interrupt_destroy( p_sys->p_timeout->interrupt );
free( p_sys->p_timeout );
}
@@ -1249,10 +1252,20 @@ static int Play( demux_t *p_demux )
{
memset( p_sys->p_timeout, 0, sizeof(timeout_thread_t) );
p_sys->p_timeout->p_demux = p_demux;
- if( vlc_clone( &p_sys->p_timeout->handle, TimeoutPrevention,
+
+ p_sys->p_timeout->interrupt = vlc_interrupt_create();
+
+ if( !p_sys->p_timeout->interrupt )
+ {
+ msg_Err( p_demux, "cannot setup interrupt context for liveMedia timout thread" );
+ free( p_sys->p_timeout );
+ p_sys->p_timeout = NULL;
+ }
+ else if( vlc_clone( &p_sys->p_timeout->handle, TimeoutPrevention,
p_sys->p_timeout, VLC_THREAD_PRIORITY_LOW ) )
{
msg_Err( p_demux, "cannot spawn liveMedia timeout thread" );
+ vlc_interrupt_destroy( p_sys->p_timeout->interrupt );
free( p_sys->p_timeout );
p_sys->p_timeout = NULL;
}
@@ -2128,6 +2141,8 @@ static void* TimeoutPrevention( void *p_data )
demux_t *p_demux = p_timeout->p_demux;
demux_sys_t *p_sys = p_demux->p_sys;
+ vlc_interrupt_set( p_timeout->interrupt );
+
for( ;; )
{
/* Voodoo (= no) thread safety here! *Ahem* */
@@ -2153,7 +2168,7 @@ static void* TimeoutPrevention( void *p_data )
}
p_sys->b_timeout_call = !p_timeout->b_handle_keep_alive;
- msleep (((int64_t)p_sys->i_timeout - 2) * CLOCK_FREQ);
+ vlc_msleep_i11e( ((int64_t)p_sys->i_timeout - 2) * CLOCK_FREQ );
}
vlc_assert_unreachable(); /* dead code */
}
--
2.9.2
More information about the vlc-devel
mailing list