[15/16] winecoreaudio: Move a memset out of a mutex-guarded section.

Ken Thomases ken at codeweavers.com
Thu Dec 21 03:50:09 CST 2006


This reduces the amount of time the mutex is held.  It also allows for
some simplification of the loop structure.
---
  dlls/winmm/winecoreaudio/audio.c |   61 +++++++++++++++++++-------------------
  1 files changed, 30 insertions(+), 31 deletions(-)
-------------- next part --------------
diff --git a/dlls/winmm/winecoreaudio/audio.c b/dlls/winmm/winecoreaudio/audio.c
index 94fe157..bd0c206 100644
--- a/dlls/winmm/winecoreaudio/audio.c
+++ b/dlls/winmm/winecoreaudio/audio.c
@@ -1366,47 +1366,46 @@ OSStatus CoreAudio_woAudioUnitIOProc(voi
 
     pthread_mutex_lock(&wwo->lock);
 
-    while (dataNeeded > 0)
+    while (dataNeeded > 0 && wwo->state == WINE_WS_PLAYING && wwo->lpPlayPtr)
     {
-        if (wwo->state == WINE_WS_PLAYING && wwo->lpPlayPtr)
-        {
-            unsigned int available = wwo->lpPlayPtr->dwBufferLength - wwo->dwPartialOffset;
-            unsigned int toCopy;
-
-            if (available >= dataNeeded)
-                toCopy = dataNeeded;
-            else
-                toCopy = available;
+        unsigned int available = wwo->lpPlayPtr->dwBufferLength - wwo->dwPartialOffset;
+        unsigned int toCopy;
 
-            if (toCopy > 0)
-            {
-                memcpy((char*)ioData->mBuffers[0].mData + dataProvided,
-                    wwo->lpPlayPtr->lpData + wwo->dwPartialOffset, toCopy);
-                wwo->dwPartialOffset += toCopy;
-                wwo->dwPlayedTotal += toCopy;
-                dataProvided += toCopy;
-                dataNeeded -= toCopy;
-                available -= toCopy;
-            }
+        if (available >= dataNeeded)
+            toCopy = dataNeeded;
+        else
+            toCopy = available;
 
-            if (available == 0)
-            {
-                wodHelper_PlayPtrNext(wwo);
-                needNotify = 1;
-            }
+        if (toCopy > 0)
+        {
+            memcpy((char*)ioData->mBuffers[0].mData + dataProvided,
+                wwo->lpPlayPtr->lpData + wwo->dwPartialOffset, toCopy);
+            wwo->dwPartialOffset += toCopy;
+            wwo->dwPlayedTotal += toCopy;
+            dataProvided += toCopy;
+            dataNeeded -= toCopy;
+            available -= toCopy;
         }
-        else
+
+        if (available == 0)
         {
-            if (!dataProvided)
-                *ioActionFlags |= kAudioUnitRenderAction_OutputIsSilence;
-            memset((char*)ioData->mBuffers[0].mData + dataProvided, 0, dataNeeded);
-            dataProvided += dataNeeded;
-            dataNeeded = 0;
+            wodHelper_PlayPtrNext(wwo);
+            needNotify = 1;
         }
     }
 
     pthread_mutex_unlock(&wwo->lock);
 
+    /* We can't provide any more wave data.  Fill the rest with silence. */
+    if (dataNeeded > 0)
+    {
+        if (!dataProvided)
+            *ioActionFlags |= kAudioUnitRenderAction_OutputIsSilence;
+        memset((char*)ioData->mBuffers[0].mData + dataProvided, 0, dataNeeded);
+        dataProvided += dataNeeded;
+        dataNeeded = 0;
+    }
+
     /* We only fill buffer 0.  Set any others that might be requested to 0. */
     for (buffer = 1; buffer < ioData->mNumberBuffers; buffer++)
     {


More information about the wine-patches mailing list