From: Paul Gofman pgofman@codeweavers.com
--- dlls/winepulse.drv/pulse.c | 42 ++++++++++++++------------------------ 1 file changed, 15 insertions(+), 27 deletions(-)
diff --git a/dlls/winepulse.drv/pulse.c b/dlls/winepulse.drv/pulse.c index 9d3363e2638..726a86e299d 100644 --- a/dlls/winepulse.drv/pulse.c +++ b/dlls/winepulse.drv/pulse.c @@ -203,6 +203,16 @@ static char *wstr_to_str(const WCHAR *wstr) return str; }
+static void wait_pa_operation_complete(pa_operation *o) +{ + if (!o) + return; + + while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) + pulse_cond_wait(); + pa_operation_unref(o); +} + /* Following pulseaudio design here, mainloop has the lock taken whenever * it is handling something for pulse, and the lock is required whenever * doing any pa_* call that can affect the state in any way @@ -1548,7 +1558,6 @@ static NTSTATUS pulse_timer_loop(void *args) pa_usec_t last_time; UINT32 adv_bytes; int success; - pa_operation *o;
pulse_lock(); delay.QuadPart = -stream->mmdev_period_usec * 10; @@ -1566,13 +1575,7 @@ static NTSTATUS pulse_timer_loop(void *args)
delay.QuadPart = -stream->mmdev_period_usec * 10;
- o = pa_stream_update_timing_info(stream->stream, pulse_op_cb, &success); - if (o) - { - while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) - pulse_cond_wait(); - pa_operation_unref(o); - } + wait_pa_operation_complete(pa_stream_update_timing_info(stream->stream, pulse_op_cb, &success)); err = pa_stream_get_time(stream->stream, &now); if (err == 0) { @@ -1684,11 +1687,7 @@ static NTSTATUS pulse_start(void *args) { o = pa_stream_cork(stream->stream, 0, pulse_op_cb, &success); if (o) - { - while(pa_operation_get_state(o) == PA_OPERATION_RUNNING) - pulse_cond_wait(); - pa_operation_unref(o); - } + wait_pa_operation_complete(o); else success = 0; if (!success) @@ -1731,11 +1730,7 @@ static NTSTATUS pulse_stop(void *args) { o = pa_stream_cork(stream->stream, 1, pulse_op_cb, &success); if (o) - { - while(pa_operation_get_state(o) == PA_OPERATION_RUNNING) - pulse_cond_wait(); - pa_operation_unref(o); - } + wait_pa_operation_complete(o); else success = 0; if (!success) @@ -1779,15 +1774,8 @@ static NTSTATUS pulse_reset(void *args) /* If there is still data in the render buffer it needs to be removed from the server */ int success = 0; if (stream->held_bytes) - { - pa_operation *o = pa_stream_flush(stream->stream, pulse_op_cb, &success); - if (o) - { - while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) - pulse_cond_wait(); - pa_operation_unref(o); - } - } + wait_pa_operation_complete(pa_stream_flush(stream->stream, pulse_op_cb, &success)); + if (success || !stream->held_bytes) { stream->clock_lastpos = stream->clock_written = 0;