From c267c8e4c32bbbf7a384ed05c82af3b205f83ff1 Mon Sep 17 00:00:00 2001 From: James Laird Date: Sun, 25 Aug 2013 20:54:58 +1000 Subject: [PATCH] rtsp: treat pthread_t as properly opaque We use the mutex's state to determine whether the playing_thread is valid or not. Also now use pthread_equal, as we should. Should address issue #236. --- rtsp.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rtsp.c b/rtsp.c index 660ac14e..c6d64506 100644 --- a/rtsp.c +++ b/rtsp.c @@ -56,7 +56,7 @@ // it monitors the request variable (at least when interrupted) static pthread_mutex_t playing_mutex = PTHREAD_MUTEX_INITIALIZER; static int please_shutdown = 0; -static pthread_t playing_thread = 0; +static pthread_t playing_thread; typedef struct { int fd; @@ -66,8 +66,14 @@ typedef struct { pthread_t thread; } rtsp_conn_info; +// determine if we are the currently playing thread static inline int rtsp_playing(void) { - return playing_thread == pthread_self(); + if (pthread_mutex_trylock(&playing_mutex)) { + return pthread_equal(playing_thread, pthread_self()); + } else { + pthread_mutex_unlock(&playing_mutex); + return 0; + } } static void rtsp_take_player(void) { @@ -711,7 +717,6 @@ respond: rtp_shutdown(); player_stop(); please_shutdown = 0; - playing_thread = 0; pthread_mutex_unlock(&playing_mutex); } if (auth_nonce)