From bca3c546d28b0d4846511dbefba5bef4b3ef4a81 Mon Sep 17 00:00:00 2001 From: Alistair Leslie-Hughes Date: Sat, 11 Jan 2020 17:28:13 +1100 Subject: [PATCH] Added dsound-SRW patchset --- ...Use-an-SRW-lock-for-buffer_list_lock.patch | 166 ++++++++++++++++++ patches/dsound-SRW/definition | 1 + patches/patchinstall.sh | 19 ++ 3 files changed, 186 insertions(+) create mode 100644 patches/dsound-SRW/0001-dsound-Use-an-SRW-lock-for-buffer_list_lock.patch create mode 100644 patches/dsound-SRW/definition diff --git a/patches/dsound-SRW/0001-dsound-Use-an-SRW-lock-for-buffer_list_lock.patch b/patches/dsound-SRW/0001-dsound-Use-an-SRW-lock-for-buffer_list_lock.patch new file mode 100644 index 00000000..7728a56b --- /dev/null +++ b/patches/dsound-SRW/0001-dsound-Use-an-SRW-lock-for-buffer_list_lock.patch @@ -0,0 +1,166 @@ +From 410d340084e24732e3d7423f74dbe8aa92dddd09 Mon Sep 17 00:00:00 2001 +From: Zebediah Figura +Date: Thu, 9 Jan 2020 14:51:36 -0600 +Subject: [PATCH] dsound: Use an SRW lock for buffer_list_lock. + +Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=48408 + +Signed-off-by: Zebediah Figura +--- + dlls/dsound/buffer.c | 4 ++-- + dlls/dsound/dsound.c | 15 +++++++-------- + dlls/dsound/dsound_private.h | 2 +- + dlls/dsound/mixer.c | 4 ++-- + dlls/dsound/primary.c | 4 ++-- + 5 files changed, 14 insertions(+), 15 deletions(-) + +diff --git a/dlls/dsound/buffer.c b/dlls/dsound/buffer.c +index c61868a7820..82a23eb8907 100644 +--- a/dlls/dsound/buffer.c ++++ b/dlls/dsound/buffer.c +@@ -644,7 +644,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(IDirectSoundBuffer8 *iface, + + if (x1 || x2) + { +- RtlAcquireResourceShared(&This->device->buffer_list_lock, TRUE); ++ AcquireSRWLockShared(&This->device->buffer_list_lock); + LIST_FOR_EACH_ENTRY(iter, &This->buffer->buffers, IDirectSoundBufferImpl, entry ) + { + RtlAcquireResourceShared(&iter->lock, TRUE); +@@ -665,7 +665,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(IDirectSoundBuffer8 *iface, + } + RtlReleaseResource(&iter->lock); + } +- RtlReleaseResource(&This->device->buffer_list_lock); ++ ReleaseSRWLockShared(&This->device->buffer_list_lock); + } + + return hres; +diff --git a/dlls/dsound/dsound.c b/dlls/dsound/dsound.c +index 4dcea9e29e9..e991210621f 100644 +--- a/dlls/dsound/dsound.c ++++ b/dlls/dsound/dsound.c +@@ -181,7 +181,7 @@ static HRESULT DirectSoundDevice_Create(DirectSoundDevice ** ppDevice) + InitializeCriticalSection(&(device->mixlock)); + device->mixlock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": DirectSoundDevice.mixlock"); + +- RtlInitializeResource(&(device->buffer_list_lock)); ++ InitializeSRWLock(&device->buffer_list_lock); + + init_eax_device(device); + +@@ -242,7 +242,6 @@ static ULONG DirectSoundDevice_Release(DirectSoundDevice * device) + HeapFree(GetProcessHeap(), 0, device->tmp_buffer); + HeapFree(GetProcessHeap(), 0, device->cp_buffer); + HeapFree(GetProcessHeap(), 0, device->buffer); +- RtlDeleteResource(&device->buffer_list_lock); + device->mixlock.DebugInfo->Spare[0] = 0; + DeleteCriticalSection(&device->mixlock); + HeapFree(GetProcessHeap(),0,device); +@@ -616,7 +615,7 @@ HRESULT DirectSoundDevice_AddBuffer( + + TRACE("(%p, %p)\n", device, pDSB); + +- RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE); ++ AcquireSRWLockExclusive(&device->buffer_list_lock); + + if (device->buffers) + newbuffers = HeapReAlloc(GetProcessHeap(),0,device->buffers,sizeof(IDirectSoundBufferImpl*)*(device->nrofbuffers+1)); +@@ -633,7 +632,7 @@ HRESULT DirectSoundDevice_AddBuffer( + hr = DSERR_OUTOFMEMORY; + } + +- RtlReleaseResource(&(device->buffer_list_lock)); ++ ReleaseSRWLockExclusive(&device->buffer_list_lock); + + return hr; + } +@@ -648,7 +647,7 @@ void DirectSoundDevice_RemoveBuffer(DirectSoundDevice * device, IDirectSoundBuff + + TRACE("(%p, %p)\n", device, pDSB); + +- RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE); ++ AcquireSRWLockExclusive(&device->buffer_list_lock); + + if (device->nrofbuffers == 1) { + assert(device->buffers[0] == pDSB); +@@ -666,7 +665,7 @@ void DirectSoundDevice_RemoveBuffer(DirectSoundDevice * device, IDirectSoundBuff + device->nrofbuffers--; + TRACE("buffer count is now %d\n", device->nrofbuffers); + +- RtlReleaseResource(&(device->buffer_list_lock)); ++ ReleaseSRWLockExclusive(&device->buffer_list_lock); + } + + /******************************************************************************* +@@ -873,14 +872,14 @@ static HRESULT WINAPI IDirectSound8Impl_SetCooperativeLevel(IDirectSound8 *iface + level==DSSCL_PRIORITY ? "DSSCL_PRIORITY" : "DSSCL_EXCLUSIVE"); + } + +- RtlAcquireResourceExclusive(&device->buffer_list_lock, TRUE); ++ AcquireSRWLockExclusive(&device->buffer_list_lock); + EnterCriticalSection(&device->mixlock); + if ((level == DSSCL_WRITEPRIMARY) != (device->priolevel == DSSCL_WRITEPRIMARY)) + hr = DSOUND_ReopenDevice(device, level == DSSCL_WRITEPRIMARY); + if (SUCCEEDED(hr)) + device->priolevel = level; + LeaveCriticalSection(&device->mixlock); +- RtlReleaseResource(&device->buffer_list_lock); ++ ReleaseSRWLockExclusive(&device->buffer_list_lock); + return hr; + } + +diff --git a/dlls/dsound/dsound_private.h b/dlls/dsound/dsound_private.h +index dcb67d56948..87786c6b11b 100644 +--- a/dlls/dsound/dsound_private.h ++++ b/dlls/dsound/dsound_private.h +@@ -83,7 +83,7 @@ struct DirectSoundDevice + DWORD writelead, buflen, ac_frames, frag_frames, playpos, pad, stopped; + int nrofbuffers; + IDirectSoundBufferImpl** buffers; +- RTL_RWLOCK buffer_list_lock; ++ RTL_SRWLOCK buffer_list_lock; + CRITICAL_SECTION mixlock; + IDirectSoundBufferImpl *primary; + DWORD speaker_config; +diff --git a/dlls/dsound/mixer.c b/dlls/dsound/mixer.c +index 023622a9f98..3006d249d43 100644 +--- a/dlls/dsound/mixer.c ++++ b/dlls/dsound/mixer.c +@@ -856,9 +856,9 @@ DWORD CALLBACK DSOUND_mixthread(void *p) + if (!dev->ref) + break; + +- RtlAcquireResourceShared(&(dev->buffer_list_lock), TRUE); ++ AcquireSRWLockShared(&dev->buffer_list_lock); + DSOUND_PerformMix(dev); +- RtlReleaseResource(&(dev->buffer_list_lock)); ++ ReleaseSRWLockShared(&dev->buffer_list_lock); + } + return 0; + } +diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c +index 852ec51b7ff..8d42fe0ed90 100644 +--- a/dlls/dsound/primary.c ++++ b/dlls/dsound/primary.c +@@ -472,7 +472,7 @@ HRESULT primarybuffer_SetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX passe + } + + /* **** */ +- RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE); ++ AcquireSRWLockExclusive(&device->buffer_list_lock); + EnterCriticalSection(&(device->mixlock)); + + if (device->priolevel == DSSCL_WRITEPRIMARY) { +@@ -508,7 +508,7 @@ HRESULT primarybuffer_SetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX passe + + out: + LeaveCriticalSection(&(device->mixlock)); +- RtlReleaseResource(&(device->buffer_list_lock)); ++ ReleaseSRWLockExclusive(&device->buffer_list_lock); + /* **** */ + + return err; +-- +2.24.1 + diff --git a/patches/dsound-SRW/definition b/patches/dsound-SRW/definition new file mode 100644 index 00000000..9edc4f6a --- /dev/null +++ b/patches/dsound-SRW/definition @@ -0,0 +1 @@ +Fixes: [48408] dsound: Use an SRW lock for buffer_list_lock. diff --git a/patches/patchinstall.sh b/patches/patchinstall.sh index f8d4dae0..5f2c6df1 100755 --- a/patches/patchinstall.sh +++ b/patches/patchinstall.sh @@ -139,6 +139,7 @@ patch_enable_all () enable_dsdmo_new_dll="$1" enable_dsound_EAX="$1" enable_dsound_Fast_Mixer="$1" + enable_dsound_SRW="$1" enable_dwmapi_DwmGetTransportAttributes="$1" enable_dwrite_FontFallback="$1" enable_dxdiagn_Enumerate_DirectSound="$1" @@ -552,6 +553,9 @@ patch_enable () dsound-Fast_Mixer) enable_dsound_Fast_Mixer="$2" ;; + dsound-SRW) + enable_dsound_SRW="$2" + ;; dwmapi-DwmGetTransportAttributes) enable_dwmapi_DwmGetTransportAttributes="$2" ;; @@ -3410,6 +3414,21 @@ if test "$enable_dsound_EAX" -eq 1; then ) >> "$patchlist" fi +# Patchset dsound-SRW +# | +# | This patchset fixes the following Wine bugs: +# | * [#48408] dsound: Use an SRW lock for buffer_list_lock. +# | +# | Modified files: +# | * dlls/dsound/buffer.c, dlls/dsound/dsound.c, dlls/dsound/dsound_private.h, dlls/dsound/mixer.c, dlls/dsound/primary.c +# | +if test "$enable_dsound_SRW" -eq 1; then + patch_apply dsound-SRW/0001-dsound-Use-an-SRW-lock-for-buffer_list_lock.patch + ( + printf '%s\n' '+ { "Zebediah Figura", "dsound: Use an SRW lock for buffer_list_lock.", 1 },'; + ) >> "$patchlist" +fi + # Patchset dwmapi-DwmGetTransportAttributes # | # | This patchset fixes the following Wine bugs: