[vlc-devel] [PATCH 6/7] mms: use semaphore rather than cancellation
RĂ©mi Denis-Courmont
remi at remlab.net
Sun Feb 16 18:50:45 CET 2020
---
modules/access/mms/mmstu.c | 25 ++++++++++---------------
modules/access/mms/mmstu.h | 5 ++++-
2 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/modules/access/mms/mmstu.c b/modules/access/mms/mmstu.c
index ad0efc8f99..d96cf22289 100644
--- a/modules/access/mms/mmstu.c
+++ b/modules/access/mms/mmstu.c
@@ -33,7 +33,6 @@
#include <errno.h>
#include <assert.h>
-#include <stdnoreturn.h>
#include <sys/types.h>
#include <unistd.h>
@@ -1585,22 +1584,17 @@ static int mms_HeaderMediaRead( stream_t *p_access, int i_type )
return -1;
}
-noreturn static void *KeepAliveThread( void *p_data )
+static void *KeepAliveThread( void *p_data )
{
stream_t *p_access = p_data;
+ access_sys_t *p_sys = p_access->p_sys;
- for( ;; )
- {
- /* Send keep-alive every ten seconds */
- int canc = vlc_savecancel();
-
+ do /* Send keep-alive every ten seconds */
mms_CommandSend( p_access, 0x1b, 0, 0, NULL, 0 );
+ while (vlc_sem_timedwait( &p_sys->keep_alive.sem,
+ vlc_tick_now() + VLC_TICK_FROM_SEC(10) ));
- vlc_restorecancel( canc );
-
- vlc_tick_sleep( VLC_TICK_FROM_SEC(10) );
- }
- vlc_assert_unreachable();
+ return NULL;
}
static void KeepAliveStart( stream_t *p_access )
@@ -1609,7 +1603,8 @@ static void KeepAliveStart( stream_t *p_access )
if( p_sys->b_keep_alive )
return;
- p_sys->b_keep_alive = !vlc_clone( &p_sys->keep_alive,
+ vlc_sem_init( &p_sys->keep_alive.sem, 0 );
+ p_sys->b_keep_alive = !vlc_clone( &p_sys->keep_alive.thread,
KeepAliveThread, p_access,
VLC_THREAD_PRIORITY_LOW );
}
@@ -1620,7 +1615,7 @@ static void KeepAliveStop( stream_t *p_access )
if( !p_sys->b_keep_alive )
return;
- vlc_cancel( p_sys->keep_alive );
- vlc_join( p_sys->keep_alive, NULL );
+ vlc_sem_post( &p_sys->keep_alive.sem );
+ vlc_join( p_sys->keep_alive.thread, NULL );
p_sys->b_keep_alive = false;
}
diff --git a/modules/access/mms/mmstu.h b/modules/access/mms/mmstu.h
index 3c039a983f..a335111d1f 100644
--- a/modules/access/mms/mmstu.h
+++ b/modules/access/mms/mmstu.h
@@ -92,7 +92,10 @@ typedef struct
vlc_mutex_t lock_netwrite;
bool b_keep_alive;
- vlc_thread_t keep_alive;
+ struct {
+ vlc_thread_t thread;
+ vlc_sem_t sem;
+ } keep_alive;
} access_sys_t;
#endif
--
2.25.0
More information about the vlc-devel
mailing list