dsound: Use an SRW lock for the buffer lock.

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Andrew Eikum <aeikum@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
feature/deterministic
Zebediah Figura 2020-02-03 09:02:56 -06:00 committed by Alexandre Julliard
parent 1308700843
commit e091903999
11 changed files with 29 additions and 55 deletions

View File

@ -27,7 +27,6 @@
#include "winbase.h" #include "winbase.h"
#include "winuser.h" #include "winuser.h"
#include "mmsystem.h" #include "mmsystem.h"
#include "winternl.h"
#include "vfwmsgs.h" #include "vfwmsgs.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "dsound.h" #include "dsound.h"
@ -200,8 +199,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetVolume(IDirectSoundBuffer8 *ifac
return DSERR_INVALIDPARAM; return DSERR_INVALIDPARAM;
} }
/* **** */ AcquireSRWLockExclusive(&This->lock);
RtlAcquireResourceExclusive(&This->lock, TRUE);
if (This->dsbd.dwFlags & DSBCAPS_CTRL3D) { if (This->dsbd.dwFlags & DSBCAPS_CTRL3D) {
oldVol = This->ds3db_lVolume; oldVol = This->ds3db_lVolume;
@ -216,8 +214,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetVolume(IDirectSoundBuffer8 *ifac
DSOUND_RecalcVolPan(&(This->volpan)); DSOUND_RecalcVolPan(&(This->volpan));
} }
RtlReleaseResource(&This->lock); ReleaseSRWLockExclusive(&This->lock);
/* **** */
return hres; return hres;
} }
@ -268,8 +265,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(IDirectSoundBuffer8 *i
return DSERR_INVALIDPARAM; return DSERR_INVALIDPARAM;
} }
/* **** */ AcquireSRWLockExclusive(&This->lock);
RtlAcquireResourceExclusive(&This->lock, TRUE);
oldFreq = This->freq; oldFreq = This->freq;
This->freq = freq; This->freq = freq;
@ -280,8 +276,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(IDirectSoundBuffer8 *i
DSOUND_RecalcFormat(This); DSOUND_RecalcFormat(This);
} }
RtlReleaseResource(&This->lock); ReleaseSRWLockExclusive(&This->lock);
/* **** */
return DS_OK; return DS_OK;
} }
@ -295,8 +290,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Play(IDirectSoundBuffer8 *iface, DW
TRACE("(%p,%08x,%08x,%08x)\n",This,reserved1,reserved2,flags); TRACE("(%p,%08x,%08x,%08x)\n",This,reserved1,reserved2,flags);
/* **** */ AcquireSRWLockExclusive(&This->lock);
RtlAcquireResourceExclusive(&This->lock, TRUE);
This->playflags = flags; This->playflags = flags;
if (This->state == STATE_STOPPED) { if (This->state == STATE_STOPPED) {
@ -309,8 +303,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Play(IDirectSoundBuffer8 *iface, DW
IMediaObject_Discontinuity(This->filters[i].obj, 0); IMediaObject_Discontinuity(This->filters[i].obj, 0);
} }
RtlReleaseResource(&This->lock); ReleaseSRWLockExclusive(&This->lock);
/* **** */
return hres; return hres;
} }
@ -322,8 +315,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Stop(IDirectSoundBuffer8 *iface)
TRACE("(%p)\n",This); TRACE("(%p)\n",This);
/* **** */ AcquireSRWLockExclusive(&This->lock);
RtlAcquireResourceExclusive(&This->lock, TRUE);
if (This->state == STATE_PLAYING) if (This->state == STATE_PLAYING)
This->state = STATE_STOPPING; This->state = STATE_STOPPING;
@ -333,8 +325,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Stop(IDirectSoundBuffer8 *iface)
DSOUND_CheckEvent(This, 0, 0); DSOUND_CheckEvent(This, 0, 0);
} }
RtlReleaseResource(&This->lock); ReleaseSRWLockExclusive(&This->lock);
/* **** */
return hres; return hres;
} }
@ -382,7 +373,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(IDirectSoundBuff
TRACE("(%p,%p,%p)\n",This,playpos,writepos); TRACE("(%p,%p,%p)\n",This,playpos,writepos);
RtlAcquireResourceShared(&This->lock, TRUE); AcquireSRWLockShared(&This->lock);
pos = This->sec_mixpos; pos = This->sec_mixpos;
@ -403,7 +394,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(IDirectSoundBuff
*writepos %= This->buflen; *writepos %= This->buflen;
} }
RtlReleaseResource(&This->lock); ReleaseSRWLockShared(&This->lock);
TRACE("playpos = %d, writepos = %d, buflen=%d (%p, time=%d)\n", TRACE("playpos = %d, writepos = %d, buflen=%d (%p, time=%d)\n",
playpos?*playpos:-1, writepos?*writepos:-1, This->buflen, This, GetTickCount()); playpos?*playpos:-1, writepos?*writepos:-1, This->buflen, This, GetTickCount());
@ -423,13 +414,13 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetStatus(IDirectSoundBuffer8 *ifac
} }
*status = 0; *status = 0;
RtlAcquireResourceShared(&This->lock, TRUE); AcquireSRWLockShared(&This->lock);
if ((This->state == STATE_STARTING) || (This->state == STATE_PLAYING)) { if ((This->state == STATE_STARTING) || (This->state == STATE_PLAYING)) {
*status |= DSBSTATUS_PLAYING; *status |= DSBSTATUS_PLAYING;
if (This->playflags & DSBPLAY_LOOPING) if (This->playflags & DSBPLAY_LOOPING)
*status |= DSBSTATUS_LOOPING; *status |= DSBSTATUS_LOOPING;
} }
RtlReleaseResource(&This->lock); ReleaseSRWLockShared(&This->lock);
TRACE("status=%x\n", *status); TRACE("status=%x\n", *status);
return DS_OK; return DS_OK;
@ -509,8 +500,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Lock(IDirectSoundBuffer8 *iface, DW
return DSERR_INVALIDPARAM; return DSERR_INVALIDPARAM;
} }
/* **** */ AcquireSRWLockShared(&This->lock);
RtlAcquireResourceShared(&This->lock, TRUE);
if (writecursor+writebytes <= This->buflen) { if (writecursor+writebytes <= This->buflen) {
*(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor; *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
@ -543,8 +533,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Lock(IDirectSoundBuffer8 *iface, DW
TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n", *(LPBYTE*)lplpaudioptr1, *audiobytes1, lplpaudioptr2 ? *(LPBYTE*)lplpaudioptr2 : NULL, audiobytes2 ? *audiobytes2: 0, writecursor); TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n", *(LPBYTE*)lplpaudioptr1, *audiobytes1, lplpaudioptr2 ? *(LPBYTE*)lplpaudioptr2 : NULL, audiobytes2 ? *audiobytes2: 0, writecursor);
} }
RtlReleaseResource(&This->lock); ReleaseSRWLockShared(&This->lock);
/* **** */
return DS_OK; return DS_OK;
} }
@ -557,8 +546,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetCurrentPosition(IDirectSoundBuff
TRACE("(%p,%d)\n",This,newpos); TRACE("(%p,%d)\n",This,newpos);
/* **** */ AcquireSRWLockExclusive(&This->lock);
RtlAcquireResourceExclusive(&This->lock, TRUE);
/* start mixing from this new location instead */ /* start mixing from this new location instead */
newpos %= This->buflen; newpos %= This->buflen;
@ -568,8 +556,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetCurrentPosition(IDirectSoundBuff
/* at this point, do not attempt to reset buffers, mess with primary mix position, /* at this point, do not attempt to reset buffers, mess with primary mix position,
or anything like that to reduce latency. The data already prebuffered cannot be changed */ or anything like that to reduce latency. The data already prebuffered cannot be changed */
RtlReleaseResource(&This->lock); ReleaseSRWLockExclusive(&This->lock);
/* **** */
return hres; return hres;
} }
@ -591,16 +578,14 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetPan(IDirectSoundBuffer8 *iface,
return DSERR_CONTROLUNAVAIL; return DSERR_CONTROLUNAVAIL;
} }
/* **** */ AcquireSRWLockExclusive(&This->lock);
RtlAcquireResourceExclusive(&This->lock, TRUE);
if (This->volpan.lPan != pan) { if (This->volpan.lPan != pan) {
This->volpan.lPan = pan; This->volpan.lPan = pan;
DSOUND_RecalcVolPan(&(This->volpan)); DSOUND_RecalcVolPan(&(This->volpan));
} }
RtlReleaseResource(&This->lock); ReleaseSRWLockExclusive(&This->lock);
/* **** */
return hres; return hres;
} }
@ -646,7 +631,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(IDirectSoundBuffer8 *iface,
AcquireSRWLockShared(&This->device->buffer_list_lock); AcquireSRWLockShared(&This->device->buffer_list_lock);
LIST_FOR_EACH_ENTRY(iter, &This->buffer->buffers, IDirectSoundBufferImpl, entry ) LIST_FOR_EACH_ENTRY(iter, &This->buffer->buffers, IDirectSoundBufferImpl, entry )
{ {
RtlAcquireResourceShared(&iter->lock, TRUE); AcquireSRWLockShared(&iter->lock);
if (x1) if (x1)
{ {
if(x1 + (DWORD_PTR)p1 - (DWORD_PTR)iter->buffer->memory > iter->buflen) if(x1 + (DWORD_PTR)p1 - (DWORD_PTR)iter->buffer->memory > iter->buflen)
@ -662,7 +647,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(IDirectSoundBuffer8 *iface,
else else
iter->buffer->lockedbytes -= x2; iter->buffer->lockedbytes -= x2;
} }
RtlReleaseResource(&iter->lock); ReleaseSRWLockShared(&iter->lock);
} }
ReleaseSRWLockShared(&This->device->buffer_list_lock); ReleaseSRWLockShared(&This->device->buffer_list_lock);
} }
@ -1125,7 +1110,7 @@ HRESULT secondarybuffer_create(DirectSoundDevice *device, const DSBUFFERDESC *ds
} else } else
DSOUND_RecalcVolPan(&(dsb->volpan)); DSOUND_RecalcVolPan(&(dsb->volpan));
RtlInitializeResource(&dsb->lock); InitializeSRWLock(&dsb->lock);
/* register buffer */ /* register buffer */
err = DirectSoundDevice_AddBuffer(device, dsb); err = DirectSoundDevice_AddBuffer(device, dsb);
@ -1148,7 +1133,6 @@ void secondarybuffer_destroy(IDirectSoundBufferImpl *This)
This->device->drvcaps.dwFreeHwMixingAllBuffers++; This->device->drvcaps.dwFreeHwMixingAllBuffers++;
DirectSoundDevice_RemoveBuffer(This->device, This); DirectSoundDevice_RemoveBuffer(This->device, This);
RtlDeleteResource(&This->lock);
This->buffer->ref--; This->buffer->ref--;
list_remove(&This->entry); list_remove(&This->entry);
@ -1190,13 +1174,13 @@ HRESULT IDirectSoundBufferImpl_Duplicate(
return DSERR_OUTOFMEMORY; return DSERR_OUTOFMEMORY;
} }
RtlAcquireResourceShared(&pdsb->lock, TRUE); AcquireSRWLockShared(&pdsb->lock);
CopyMemory(dsb, pdsb, sizeof(*dsb)); CopyMemory(dsb, pdsb, sizeof(*dsb));
dsb->pwfx = DSOUND_CopyFormat(pdsb->pwfx); dsb->pwfx = DSOUND_CopyFormat(pdsb->pwfx);
RtlReleaseResource(&pdsb->lock); ReleaseSRWLockShared(&pdsb->lock);
if (dsb->pwfx == NULL) { if (dsb->pwfx == NULL) {
HeapFree(GetProcessHeap(),0,dsb); HeapFree(GetProcessHeap(),0,dsb);
@ -1218,12 +1202,11 @@ HRESULT IDirectSoundBufferImpl_Duplicate(
dsb->device = device; dsb->device = device;
DSOUND_RecalcFormat(dsb); DSOUND_RecalcFormat(dsb);
RtlInitializeResource(&dsb->lock); InitializeSRWLock(&dsb->lock);
/* register buffer */ /* register buffer */
hres = DirectSoundDevice_AddBuffer(device, dsb); hres = DirectSoundDevice_AddBuffer(device, dsb);
if (hres != DS_OK) { if (hres != DS_OK) {
RtlDeleteResource(&dsb->lock);
list_remove(&dsb->entry); list_remove(&dsb->entry);
dsb->buffer->ref--; dsb->buffer->ref--;
HeapFree(GetProcessHeap(),0,dsb->pwfx); HeapFree(GetProcessHeap(),0,dsb->pwfx);

View File

@ -34,7 +34,6 @@
#include "winuser.h" #include "winuser.h"
#include "mmsystem.h" #include "mmsystem.h"
#include "mmddk.h" #include "mmddk.h"
#include "winternl.h"
#include "winnls.h" #include "winnls.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "dsound.h" #include "dsound.h"

View File

@ -30,7 +30,6 @@
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "winuser.h" #include "winuser.h"
#include "winternl.h"
#include "mmddk.h" #include "mmddk.h"
#include "wingdi.h" #include "wingdi.h"
#include "mmreg.h" #include "mmreg.h"

View File

@ -41,7 +41,6 @@
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "mmsystem.h" #include "mmsystem.h"
#include "winternl.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "dsound.h" #include "dsound.h"
#include "dsound_private.h" #include "dsound_private.h"

View File

@ -43,7 +43,6 @@
#include "winnls.h" #include "winnls.h"
#include "winreg.h" #include "winreg.h"
#include "mmsystem.h" #include "mmsystem.h"
#include "winternl.h"
#include "mmddk.h" #include "mmddk.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "dsound.h" #include "dsound.h"

View File

@ -136,7 +136,7 @@ struct IDirectSoundBufferImpl
LONG ref, refn, ref3D, refiks; LONG ref, refn, ref3D, refiks;
/* IDirectSoundBufferImpl fields */ /* IDirectSoundBufferImpl fields */
DirectSoundDevice* device; DirectSoundDevice* device;
RTL_RWLOCK lock; SRWLOCK lock;
PWAVEFORMATEX pwfx; PWAVEFORMATEX pwfx;
BufferMemory* buffer; BufferMemory* buffer;
DWORD playflags,state,leadin; DWORD playflags,state,leadin;

View File

@ -28,7 +28,6 @@
#include "winuser.h" #include "winuser.h"
#include "mmsystem.h" #include "mmsystem.h"
#include "mmddk.h" #include "mmddk.h"
#include "winternl.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "dsound.h" #include "dsound.h"
#include "dsound_private.h" #include "dsound_private.h"

View File

@ -33,7 +33,6 @@
#include "mmsystem.h" #include "mmsystem.h"
#include "wingdi.h" #include "wingdi.h"
#include "mmreg.h" #include "mmreg.h"
#include "winternl.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "dsound.h" #include "dsound.h"
#include "ks.h" #include "ks.h"
@ -593,7 +592,7 @@ static void DSOUND_MixToPrimary(const DirectSoundDevice *device, float *mix_buff
if (dsb->buflen && dsb->state) { if (dsb->buflen && dsb->state) {
TRACE("Checking %p, frames=%d\n", dsb, frames); TRACE("Checking %p, frames=%d\n", dsb, frames);
RtlAcquireResourceShared(&dsb->lock, TRUE); AcquireSRWLockShared(&dsb->lock);
/* if buffer is stopping it is stopped now */ /* if buffer is stopping it is stopped now */
if (dsb->state == STATE_STOPPING) { if (dsb->state == STATE_STOPPING) {
dsb->state = STATE_STOPPED; dsb->state = STATE_STOPPED;
@ -609,7 +608,7 @@ static void DSOUND_MixToPrimary(const DirectSoundDevice *device, float *mix_buff
*all_stopped = FALSE; *all_stopped = FALSE;
} }
RtlReleaseResource(&dsb->lock); ReleaseSRWLockShared(&dsb->lock);
} }
} }
} }

View File

@ -32,7 +32,6 @@
#include "winbase.h" #include "winbase.h"
#include "winuser.h" #include "winuser.h"
#include "mmsystem.h" #include "mmsystem.h"
#include "winternl.h"
#include "mmddk.h" #include "mmddk.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "dsound.h" #include "dsound.h"
@ -274,9 +273,9 @@ static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device, WAVEFORMATEX *wfx,
device->playpos = 0; device->playpos = 0;
for (i = 0; i < device->nrofbuffers; i++) { for (i = 0; i < device->nrofbuffers; i++) {
RtlAcquireResourceExclusive(&dsb[i]->lock, TRUE); AcquireSRWLockExclusive(&dsb[i]->lock);
DSOUND_RecalcFormat(dsb[i]); DSOUND_RecalcFormat(dsb[i]);
RtlReleaseResource(&dsb[i]->lock); ReleaseSRWLockExclusive(&dsb[i]->lock);
} }
return DS_OK; return DS_OK;

View File

@ -28,7 +28,6 @@
#include "winbase.h" #include "winbase.h"
#include "winuser.h" #include "winuser.h"
#include "mmsystem.h" #include "mmsystem.h"
#include "winternl.h"
#include "winnls.h" #include "winnls.h"
#include "vfwmsgs.h" #include "vfwmsgs.h"
#include "mmddk.h" #include "mmddk.h"

View File

@ -44,7 +44,6 @@
#include "winbase.h" #include "winbase.h"
#include "winuser.h" #include "winuser.h"
#include "mmsystem.h" #include "mmsystem.h"
#include "winternl.h"
#include "mmddk.h" #include "mmddk.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "dsound.h" #include "dsound.h"