]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
audio_pw.c: use pthread_setcancelstate to protect the mainloop locking
authorLukas Rusak <lorusak@gmail.com>
Thu, 23 Jun 2022 17:37:59 +0000 (10:37 -0700)
committerLukas Rusak <lorusak@gmail.com>
Thu, 23 Jun 2022 17:37:59 +0000 (10:37 -0700)
audio_pw.c

index 52e6a8824a1a9f93de8240cfc91db225a4316f09..b9315cff908d38714f55310ad5799eb400928ec5 100644 (file)
@@ -178,6 +178,8 @@ static void deinit() {
     pw_properties_free(data.props);
     data.props = NULL;
   }
+
+  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
 }
 
 static int init(__attribute__((unused)) int argc, __attribute__((unused)) char **argv) {
@@ -230,6 +232,7 @@ static int init(__attribute__((unused)) int argc, __attribute__((unused)) char *
     die("pw: pw_properties_new() failed: %m");
   }
 
+  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
   pw_thread_loop_lock(data.mainloop);
 
   if (pw_thread_loop_start(data.mainloop) != 0) {
@@ -256,6 +259,7 @@ static int init(__attribute__((unused)) int argc, __attribute__((unused)) char *
   data.sync = pw_core_sync(data.core, 0, data.sync);
 
   pw_thread_loop_unlock(data.mainloop);
+  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
 
   return 0;
 }
@@ -336,6 +340,8 @@ static const char *spa_format_to_str(enum spa_audio_format audio_format) {
 
 static void start(int sample_rate, int sample_format) {
 
+  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
+
   pw_thread_loop_lock(data.mainloop);
 
   const struct spa_pod *params[1];
@@ -410,22 +416,28 @@ static void start(int sample_rate, int sample_format) {
   }
 
   pw_thread_loop_unlock(data.mainloop);
+
+  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
 }
 
 static void stop() {
+  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
   pw_thread_loop_lock(data.mainloop);
 
   pw_stream_flush(data.stream, true);
 
   pw_thread_loop_unlock(data.mainloop);
+  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
 }
 
 static void flush() {
+  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
   pw_thread_loop_lock(data.mainloop);
 
   pw_stream_flush(data.stream, false);
 
   pw_thread_loop_unlock(data.mainloop);
+  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
 }
 
 static int play(void *buf, int samples) {
@@ -433,6 +445,7 @@ static int play(void *buf, int samples) {
   struct spa_buffer *spa_buffer;
   struct spa_data *spa_data;
 
+  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
   pw_thread_loop_lock(data.mainloop);
 
   if (pw_stream_get_state(data.stream, NULL) == PW_STREAM_STATE_PAUSED)
@@ -468,6 +481,8 @@ static int play(void *buf, int samples) {
 
   pw_thread_loop_unlock(data.mainloop);
 
+  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+
   return 0;
 }