From: Paul Gofman pgofman@codeweavers.com
--- dlls/winepulse.drv/pulse.c | 51 ++++++++++++-------------------------- 1 file changed, 16 insertions(+), 35 deletions(-)
diff --git a/dlls/winepulse.drv/pulse.c b/dlls/winepulse.drv/pulse.c index 9d3363e2638..dac1b40257f 100644 --- a/dlls/winepulse.drv/pulse.c +++ b/dlls/winepulse.drv/pulse.c @@ -203,6 +203,17 @@ static char *wstr_to_str(const WCHAR *wstr) return str; }
+static BOOL wait_pa_operation_complete(pa_operation *o) +{ + if (!o) + return FALSE; + + while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) + pulse_cond_wait(); + pa_operation_unref(o); + return TRUE; +} + /* 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 +1559,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 +1576,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) { @@ -1653,7 +1657,6 @@ static NTSTATUS pulse_start(void *args) struct start_params *params = args; struct pulse_stream *stream = handle_get_stream(params->stream); int success; - pa_operation *o;
params->result = S_OK; pulse_lock(); @@ -1682,14 +1685,7 @@ static NTSTATUS pulse_start(void *args)
if (pa_stream_is_corked(stream->stream)) { - 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); - } - else + if (!wait_pa_operation_complete(pa_stream_cork(stream->stream, 0, pulse_op_cb, &success))) success = 0; if (!success) params->result = E_FAIL; @@ -1708,7 +1704,6 @@ static NTSTATUS pulse_stop(void *args) { struct stop_params *params = args; struct pulse_stream *stream = handle_get_stream(params->stream); - pa_operation *o; int success;
pulse_lock(); @@ -1729,14 +1724,7 @@ static NTSTATUS pulse_stop(void *args) params->result = S_OK; if (stream->dataflow == eRender) { - 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); - } - else + if (!wait_pa_operation_complete(pa_stream_cork(stream->stream, 1, pulse_op_cb, &success))) success = 0; if (!success) params->result = E_FAIL; @@ -1779,15 +1767,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;