From 47f55d6a28b8b9cc6b48800f4f72c0a9bf7fd4af Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Mon, 24 Jan 2005 13:35:57 +0000 Subject: [PATCH] Don't allow other threads to access the primary buffer while the format is being changed. --- dlls/dsound/primary.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c index d27f507503..3d7e53b970 100644 --- a/dlls/dsound/primary.c +++ b/dlls/dsound/primary.c @@ -347,6 +347,7 @@ static HRESULT WINAPI PrimaryBufferImpl_SetFormat( /* **** */ RtlAcquireResourceExclusive(&(dsound->buffer_list_lock), TRUE); + EnterCriticalSection(&(dsound->mixlock)); if (wfex->wFormatTag == WAVE_FORMAT_PCM) { alloc_size = sizeof(WAVEFORMATEX); @@ -374,14 +375,12 @@ static HRESULT WINAPI PrimaryBufferImpl_SetFormat( if (err == DS_OK) { err = DSOUND_PrimaryOpen(dsound); if (err != DS_OK) { - WARN("DSOUND_PrimaryOpen failed\n"); - RtlReleaseResource(&(dsound->buffer_list_lock)); - return err; + WARN("DSOUND_PrimaryOpen failed\n"); + goto done; } } else { WARN("waveOutOpen failed\n"); - RtlReleaseResource(&(dsound->buffer_list_lock)); - return err; + goto done; } } else if (dsound->hwbuf) { err = IDsDriverBuffer_SetFormat(dsound->hwbuf, dsound->pwfx); @@ -394,15 +393,13 @@ static HRESULT WINAPI PrimaryBufferImpl_SetFormat( (LPVOID)&(dsound->hwbuf)); if (err != DS_OK) { WARN("IDsDriver_CreateSoundBuffer failed\n"); - RtlReleaseResource(&(dsound->buffer_list_lock)); - return err; + goto done; } if (dsound->state == STATE_PLAYING) dsound->state = STATE_STARTING; else if (dsound->state == STATE_STOPPING) dsound->state = STATE_STOPPED; } else { WARN("IDsDriverBuffer_SetFormat failed\n"); - RtlReleaseResource(&(dsound->buffer_list_lock)); - return err; + goto done; } /* FIXME: should we set err back to DS_OK in all cases ? */ } @@ -422,6 +419,8 @@ static HRESULT WINAPI PrimaryBufferImpl_SetFormat( } } +done: + LeaveCriticalSection(&(dsound->mixlock)); RtlReleaseResource(&(dsound->buffer_list_lock)); /* **** */