[vlc-devel] [PATCH] Avoid deadlock on UDP stop
Romain Vimont
rom at rom1v.com
Sun May 11 13:36:26 CEST 2014
The call to block_FifoWake() at the end of udp.c/ThreadRead() is not
sufficient to always prevent block_FifoGet() in udp.c/BlockUDP() from
blocking indefinitely: it will at most wake up the first, but following
calls (if any) will never be awakened, causing a deadlock.
A new flag keeping the "finishing" state of the UDP access is sufficient
to prevent the deadlock, avoiding unwanted calls to block_FifoGet().
Signed-off-by: Romain Vimont <rom at rom1v.com>
---
modules/access/udp.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/modules/access/udp.c b/modules/access/udp.c
index 3c18cb8..0e4fc4d 100644
--- a/modules/access/udp.c
+++ b/modules/access/udp.c
@@ -42,6 +42,7 @@
#include <vlc_access.h>
#include <vlc_network.h>
#include <vlc_block.h>
+#include <vlc_atomic.h>
#define MTU 65535
@@ -75,6 +76,7 @@ struct access_sys_t
size_t fifo_size;
block_fifo_t *fifo;
vlc_thread_t thread;
+ atomic_bool b_finishing;
};
/*****************************************************************************
@@ -166,6 +168,8 @@ static int Open( vlc_object_t *p_this )
sys->fifo_size = var_InheritInteger( p_access, "udp-buffer");
+ sys->b_finishing = false;
+
if( vlc_clone( &sys->thread, ThreadRead, p_access,
VLC_THREAD_PRIORITY_INPUT ) )
{
@@ -231,6 +235,13 @@ static block_t *BlockUDP( access_t *p_access )
{
access_sys_t *sys = p_access->p_sys;
+ if( unlikely( atomic_load( &sys->b_finishing ) ) )
+ {
+ /* We should not read data anymore */
+ p_access->info.b_eof = true;
+ return NULL;
+ }
+
return block_FifoGet( sys->fifo );
}
@@ -270,6 +281,7 @@ static void* ThreadRead( void *data )
block_FifoPut( sys->fifo, pkt );
}
+ atomic_store( &sys->b_finishing, true );
block_FifoWake( sys->fifo );
return NULL;
}
--
1.7.10.4
More information about the vlc-devel
mailing list