From e09190399904c6ae13ce256aaa2efbf9360ac8c9 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Mon, 3 Feb 2020 09:02:56 -0600 Subject: [PATCH] dsound: Use an SRW lock for the buffer lock. Signed-off-by: Zebediah Figura Signed-off-by: Andrew Eikum Signed-off-by: Alexandre Julliard --- dlls/dsound/buffer.c | 65 +++++++++++++----------------------- dlls/dsound/capture.c | 1 - dlls/dsound/dsound.c | 1 - dlls/dsound/dsound_convert.c | 1 - dlls/dsound/dsound_main.c | 1 - dlls/dsound/dsound_private.h | 2 +- dlls/dsound/duplex.c | 1 - dlls/dsound/mixer.c | 5 ++- dlls/dsound/primary.c | 5 ++- dlls/dsound/propset.c | 1 - dlls/dsound/sound3d.c | 1 - 11 files changed, 29 insertions(+), 55 deletions(-) diff --git a/dlls/dsound/buffer.c b/dlls/dsound/buffer.c index d585a7605ef..8d4a3b92fa6 100644 --- a/dlls/dsound/buffer.c +++ b/dlls/dsound/buffer.c @@ -27,7 +27,6 @@ #include "winbase.h" #include "winuser.h" #include "mmsystem.h" -#include "winternl.h" #include "vfwmsgs.h" #include "wine/debug.h" #include "dsound.h" @@ -200,8 +199,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetVolume(IDirectSoundBuffer8 *ifac return DSERR_INVALIDPARAM; } - /* **** */ - RtlAcquireResourceExclusive(&This->lock, TRUE); + AcquireSRWLockExclusive(&This->lock); if (This->dsbd.dwFlags & DSBCAPS_CTRL3D) { oldVol = This->ds3db_lVolume; @@ -216,8 +214,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetVolume(IDirectSoundBuffer8 *ifac DSOUND_RecalcVolPan(&(This->volpan)); } - RtlReleaseResource(&This->lock); - /* **** */ + ReleaseSRWLockExclusive(&This->lock); return hres; } @@ -268,8 +265,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(IDirectSoundBuffer8 *i return DSERR_INVALIDPARAM; } - /* **** */ - RtlAcquireResourceExclusive(&This->lock, TRUE); + AcquireSRWLockExclusive(&This->lock); oldFreq = This->freq; This->freq = freq; @@ -280,8 +276,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(IDirectSoundBuffer8 *i DSOUND_RecalcFormat(This); } - RtlReleaseResource(&This->lock); - /* **** */ + ReleaseSRWLockExclusive(&This->lock); 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); - /* **** */ - RtlAcquireResourceExclusive(&This->lock, TRUE); + AcquireSRWLockExclusive(&This->lock); This->playflags = flags; if (This->state == STATE_STOPPED) { @@ -309,8 +303,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Play(IDirectSoundBuffer8 *iface, DW IMediaObject_Discontinuity(This->filters[i].obj, 0); } - RtlReleaseResource(&This->lock); - /* **** */ + ReleaseSRWLockExclusive(&This->lock); return hres; } @@ -322,8 +315,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Stop(IDirectSoundBuffer8 *iface) TRACE("(%p)\n",This); - /* **** */ - RtlAcquireResourceExclusive(&This->lock, TRUE); + AcquireSRWLockExclusive(&This->lock); if (This->state == STATE_PLAYING) This->state = STATE_STOPPING; @@ -333,8 +325,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Stop(IDirectSoundBuffer8 *iface) DSOUND_CheckEvent(This, 0, 0); } - RtlReleaseResource(&This->lock); - /* **** */ + ReleaseSRWLockExclusive(&This->lock); return hres; } @@ -382,7 +373,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(IDirectSoundBuff TRACE("(%p,%p,%p)\n",This,playpos,writepos); - RtlAcquireResourceShared(&This->lock, TRUE); + AcquireSRWLockShared(&This->lock); pos = This->sec_mixpos; @@ -403,7 +394,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(IDirectSoundBuff *writepos %= This->buflen; } - RtlReleaseResource(&This->lock); + ReleaseSRWLockShared(&This->lock); TRACE("playpos = %d, writepos = %d, buflen=%d (%p, time=%d)\n", playpos?*playpos:-1, writepos?*writepos:-1, This->buflen, This, GetTickCount()); @@ -423,13 +414,13 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetStatus(IDirectSoundBuffer8 *ifac } *status = 0; - RtlAcquireResourceShared(&This->lock, TRUE); + AcquireSRWLockShared(&This->lock); if ((This->state == STATE_STARTING) || (This->state == STATE_PLAYING)) { *status |= DSBSTATUS_PLAYING; if (This->playflags & DSBPLAY_LOOPING) *status |= DSBSTATUS_LOOPING; } - RtlReleaseResource(&This->lock); + ReleaseSRWLockShared(&This->lock); TRACE("status=%x\n", *status); return DS_OK; @@ -509,8 +500,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Lock(IDirectSoundBuffer8 *iface, DW return DSERR_INVALIDPARAM; } - /* **** */ - RtlAcquireResourceShared(&This->lock, TRUE); + AcquireSRWLockShared(&This->lock); if (writecursor+writebytes <= This->buflen) { *(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); } - RtlReleaseResource(&This->lock); - /* **** */ + ReleaseSRWLockShared(&This->lock); return DS_OK; } @@ -557,8 +546,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetCurrentPosition(IDirectSoundBuff TRACE("(%p,%d)\n",This,newpos); - /* **** */ - RtlAcquireResourceExclusive(&This->lock, TRUE); + AcquireSRWLockExclusive(&This->lock); /* start mixing from this new location instead */ 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, or anything like that to reduce latency. The data already prebuffered cannot be changed */ - RtlReleaseResource(&This->lock); - /* **** */ + ReleaseSRWLockExclusive(&This->lock); return hres; } @@ -591,16 +578,14 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetPan(IDirectSoundBuffer8 *iface, return DSERR_CONTROLUNAVAIL; } - /* **** */ - RtlAcquireResourceExclusive(&This->lock, TRUE); + AcquireSRWLockExclusive(&This->lock); if (This->volpan.lPan != pan) { This->volpan.lPan = pan; DSOUND_RecalcVolPan(&(This->volpan)); } - RtlReleaseResource(&This->lock); - /* **** */ + ReleaseSRWLockExclusive(&This->lock); return hres; } @@ -646,7 +631,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(IDirectSoundBuffer8 *iface, AcquireSRWLockShared(&This->device->buffer_list_lock); LIST_FOR_EACH_ENTRY(iter, &This->buffer->buffers, IDirectSoundBufferImpl, entry ) { - RtlAcquireResourceShared(&iter->lock, TRUE); + AcquireSRWLockShared(&iter->lock); if (x1) { if(x1 + (DWORD_PTR)p1 - (DWORD_PTR)iter->buffer->memory > iter->buflen) @@ -662,7 +647,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(IDirectSoundBuffer8 *iface, else iter->buffer->lockedbytes -= x2; } - RtlReleaseResource(&iter->lock); + ReleaseSRWLockShared(&iter->lock); } ReleaseSRWLockShared(&This->device->buffer_list_lock); } @@ -1125,7 +1110,7 @@ HRESULT secondarybuffer_create(DirectSoundDevice *device, const DSBUFFERDESC *ds } else DSOUND_RecalcVolPan(&(dsb->volpan)); - RtlInitializeResource(&dsb->lock); + InitializeSRWLock(&dsb->lock); /* register buffer */ err = DirectSoundDevice_AddBuffer(device, dsb); @@ -1148,7 +1133,6 @@ void secondarybuffer_destroy(IDirectSoundBufferImpl *This) This->device->drvcaps.dwFreeHwMixingAllBuffers++; DirectSoundDevice_RemoveBuffer(This->device, This); - RtlDeleteResource(&This->lock); This->buffer->ref--; list_remove(&This->entry); @@ -1190,13 +1174,13 @@ HRESULT IDirectSoundBufferImpl_Duplicate( return DSERR_OUTOFMEMORY; } - RtlAcquireResourceShared(&pdsb->lock, TRUE); + AcquireSRWLockShared(&pdsb->lock); CopyMemory(dsb, pdsb, sizeof(*dsb)); dsb->pwfx = DSOUND_CopyFormat(pdsb->pwfx); - RtlReleaseResource(&pdsb->lock); + ReleaseSRWLockShared(&pdsb->lock); if (dsb->pwfx == NULL) { HeapFree(GetProcessHeap(),0,dsb); @@ -1218,12 +1202,11 @@ HRESULT IDirectSoundBufferImpl_Duplicate( dsb->device = device; DSOUND_RecalcFormat(dsb); - RtlInitializeResource(&dsb->lock); + InitializeSRWLock(&dsb->lock); /* register buffer */ hres = DirectSoundDevice_AddBuffer(device, dsb); if (hres != DS_OK) { - RtlDeleteResource(&dsb->lock); list_remove(&dsb->entry); dsb->buffer->ref--; HeapFree(GetProcessHeap(),0,dsb->pwfx); diff --git a/dlls/dsound/capture.c b/dlls/dsound/capture.c index 8fc27499998..10690f7df0d 100644 --- a/dlls/dsound/capture.c +++ b/dlls/dsound/capture.c @@ -34,7 +34,6 @@ #include "winuser.h" #include "mmsystem.h" #include "mmddk.h" -#include "winternl.h" #include "winnls.h" #include "wine/debug.h" #include "dsound.h" diff --git a/dlls/dsound/dsound.c b/dlls/dsound/dsound.c index e7ab7922bb7..3085d86e5b5 100644 --- a/dlls/dsound/dsound.c +++ b/dlls/dsound/dsound.c @@ -30,7 +30,6 @@ #include "windef.h" #include "winbase.h" #include "winuser.h" -#include "winternl.h" #include "mmddk.h" #include "wingdi.h" #include "mmreg.h" diff --git a/dlls/dsound/dsound_convert.c b/dlls/dsound/dsound_convert.c index 6181f04be73..4735178a9a8 100644 --- a/dlls/dsound/dsound_convert.c +++ b/dlls/dsound/dsound_convert.c @@ -41,7 +41,6 @@ #include "windef.h" #include "winbase.h" #include "mmsystem.h" -#include "winternl.h" #include "wine/debug.h" #include "dsound.h" #include "dsound_private.h" diff --git a/dlls/dsound/dsound_main.c b/dlls/dsound/dsound_main.c index 4e752be6bae..3acee554ad9 100644 --- a/dlls/dsound/dsound_main.c +++ b/dlls/dsound/dsound_main.c @@ -43,7 +43,6 @@ #include "winnls.h" #include "winreg.h" #include "mmsystem.h" -#include "winternl.h" #include "mmddk.h" #include "wine/debug.h" #include "dsound.h" diff --git a/dlls/dsound/dsound_private.h b/dlls/dsound/dsound_private.h index 5605bded905..bdb9ebee544 100644 --- a/dlls/dsound/dsound_private.h +++ b/dlls/dsound/dsound_private.h @@ -136,7 +136,7 @@ struct IDirectSoundBufferImpl LONG ref, refn, ref3D, refiks; /* IDirectSoundBufferImpl fields */ DirectSoundDevice* device; - RTL_RWLOCK lock; + SRWLOCK lock; PWAVEFORMATEX pwfx; BufferMemory* buffer; DWORD playflags,state,leadin; diff --git a/dlls/dsound/duplex.c b/dlls/dsound/duplex.c index 4a88dd89b96..cccfeba0f06 100644 --- a/dlls/dsound/duplex.c +++ b/dlls/dsound/duplex.c @@ -28,7 +28,6 @@ #include "winuser.h" #include "mmsystem.h" #include "mmddk.h" -#include "winternl.h" #include "wine/debug.h" #include "dsound.h" #include "dsound_private.h" diff --git a/dlls/dsound/mixer.c b/dlls/dsound/mixer.c index c1bd3273f58..a6402b09eff 100644 --- a/dlls/dsound/mixer.c +++ b/dlls/dsound/mixer.c @@ -33,7 +33,6 @@ #include "mmsystem.h" #include "wingdi.h" #include "mmreg.h" -#include "winternl.h" #include "wine/debug.h" #include "dsound.h" #include "ks.h" @@ -593,7 +592,7 @@ static void DSOUND_MixToPrimary(const DirectSoundDevice *device, float *mix_buff if (dsb->buflen && dsb->state) { TRACE("Checking %p, frames=%d\n", dsb, frames); - RtlAcquireResourceShared(&dsb->lock, TRUE); + AcquireSRWLockShared(&dsb->lock); /* if buffer is stopping it is stopped now */ if (dsb->state == STATE_STOPPING) { dsb->state = STATE_STOPPED; @@ -609,7 +608,7 @@ static void DSOUND_MixToPrimary(const DirectSoundDevice *device, float *mix_buff *all_stopped = FALSE; } - RtlReleaseResource(&dsb->lock); + ReleaseSRWLockShared(&dsb->lock); } } } diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c index 8d42fe0ed90..655f730b375 100644 --- a/dlls/dsound/primary.c +++ b/dlls/dsound/primary.c @@ -32,7 +32,6 @@ #include "winbase.h" #include "winuser.h" #include "mmsystem.h" -#include "winternl.h" #include "mmddk.h" #include "wine/debug.h" #include "dsound.h" @@ -274,9 +273,9 @@ static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device, WAVEFORMATEX *wfx, device->playpos = 0; for (i = 0; i < device->nrofbuffers; i++) { - RtlAcquireResourceExclusive(&dsb[i]->lock, TRUE); + AcquireSRWLockExclusive(&dsb[i]->lock); DSOUND_RecalcFormat(dsb[i]); - RtlReleaseResource(&dsb[i]->lock); + ReleaseSRWLockExclusive(&dsb[i]->lock); } return DS_OK; diff --git a/dlls/dsound/propset.c b/dlls/dsound/propset.c index 92aae8fe0ad..dcb2b871783 100644 --- a/dlls/dsound/propset.c +++ b/dlls/dsound/propset.c @@ -28,7 +28,6 @@ #include "winbase.h" #include "winuser.h" #include "mmsystem.h" -#include "winternl.h" #include "winnls.h" #include "vfwmsgs.h" #include "mmddk.h" diff --git a/dlls/dsound/sound3d.c b/dlls/dsound/sound3d.c index 27fc416676f..06dbf58ca0b 100644 --- a/dlls/dsound/sound3d.c +++ b/dlls/dsound/sound3d.c @@ -44,7 +44,6 @@ #include "winbase.h" #include "winuser.h" #include "mmsystem.h" -#include "winternl.h" #include "mmddk.h" #include "wine/debug.h" #include "dsound.h"