From 86e94064c0d89f5ea895bf1da973693ea4e275bb Mon Sep 17 00:00:00 2001 From: James Laird Date: Mon, 1 Apr 2013 20:08:28 +1100 Subject: [PATCH] fix potential deadlock while shutting down --- rtsp.c | 2 +- shairport.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/rtsp.c b/rtsp.c index 47908f90..92e560e0 100644 --- a/rtsp.c +++ b/rtsp.c @@ -36,7 +36,7 @@ static inline int rtsp_playing(void) { static void rtsp_take_player(void) { if (pthread_mutex_trylock(&playing_mutex)) { - debug("another thread is playing, shutting it down\n"); + debug("shutting down playing thread\n"); // XXX minor race condition between please_shutdown and signal delivery please_shutdown = 1; pthread_kill(playing_thread, SIGUSR1); diff --git a/shairport.c b/shairport.c index 6cbe6987..ffb113cc 100644 --- a/shairport.c +++ b/shairport.c @@ -4,8 +4,11 @@ #include "rtsp.h" #include "mdns.h" - +static int shutting_down = 0; static void shutdown(void) { + if (shutting_down) + return; + shutting_down = 1; printf("Shutting down...\n"); mdns_unregister(); rtsp_shutdown_stream();