]> code.delx.au - pulseaudio/commitdiff
thread-mainloop: Fix bug in example code
authorMitchell Fang <mitchell.fang@gmail.com>
Wed, 22 May 2013 08:23:27 +0000 (11:23 +0300)
committerArun Raghavan <arun.raghavan@collabora.co.uk>
Mon, 3 Jun 2013 19:08:43 +0000 (00:38 +0530)
Checking the operation state caused a deadlock, because the state
won't change before my_drain_callback() returns, and it doesn't
return before my_drain_stream_func() calls
pa_threaded_mainloop_accept().

src/pulse/thread-mainloop.h

index ff166f846da70c5a3c2aedcdcd1b27dad4bc845d..34370012e33f9e8a5d8edf9c8cba2a49e67c9b28 100644 (file)
@@ -166,7 +166,7 @@ PA_C_DECL_BEGIN
  * access this data safely, we must extend our example a bit:
  *
  * \code
- * static int *drain_result;
+ * static volatile int *drain_result = NULL;
  *
  * static void my_drain_callback(pa_stream*s, int success, void *userdata) {
  *     pa_threaded_mainloop *m;
@@ -187,7 +187,7 @@ PA_C_DECL_BEGIN
  *     o = pa_stream_drain(s, my_drain_callback, m);
  *     assert(o);
  *
- *     while (pa_operation_get_state(o) == PA_OPERATION_RUNNING)
+ *     while (drain_result == NULL)
  *         pa_threaded_mainloop_wait(m);
  *
  *     pa_operation_unref(o);