[4/6] qmgr: Add a mutex to BackgroundCopyFile.

Dan Hipschman dsh at linux.ucla.edu
Thu Mar 6 21:06:27 CST 2008


Adds mutex protection on file progress.

---
 dlls/qmgr/file.c |   12 ++++++++++++
 dlls/qmgr/qmgr.h |    1 +
 2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/dlls/qmgr/file.c b/dlls/qmgr/file.c
index 93ffba4..1377c83 100644
--- a/dlls/qmgr/file.c
+++ b/dlls/qmgr/file.c
@@ -25,6 +25,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(qmgr);
 
 static void BackgroundCopyFileDestructor(BackgroundCopyFileImpl *This)
 {
+    CloseHandle(This->mutex);
     HeapFree(GetProcessHeap(), 0, This->info.LocalName);
     HeapFree(GetProcessHeap(), 0, This->info.RemoteName);
     HeapFree(GetProcessHeap(), 0, This);
@@ -105,9 +106,11 @@ static HRESULT WINAPI BITS_IBackgroundCopyFile_GetProgress(
 {
     BackgroundCopyFileImpl *This = (BackgroundCopyFileImpl *) iface;
 
+    WaitForSingleObject(This->mutex, INFINITE);
     pVal->BytesTotal = This->fileProgress.BytesTotal;
     pVal->BytesTransferred = This->fileProgress.BytesTransferred;
     pVal->Completed = This->fileProgress.Completed;
+    ReleaseMutex(This->mutex);
 
     return S_OK;
 }
@@ -135,10 +138,18 @@ HRESULT BackgroundCopyFileConstructor(LPCWSTR remoteName,
     if (!This)
         return E_OUTOFMEMORY;
 
+    This->mutex = CreateMutexW(NULL, FALSE, NULL);
+    if (!This->mutex)
+    {
+        HeapFree(GetProcessHeap(), 0, This);
+        return E_OUTOFMEMORY;
+    }
+
     n = (lstrlenW(remoteName) + 1) * sizeof(WCHAR);
     This->info.RemoteName = HeapAlloc(GetProcessHeap(), 0, n);
     if (!This->info.RemoteName)
     {
+        CloseHandle(This->mutex);
         HeapFree(GetProcessHeap(), 0, This);
         return E_OUTOFMEMORY;
     }
@@ -148,6 +159,7 @@ HRESULT BackgroundCopyFileConstructor(LPCWSTR remoteName,
     This->info.LocalName = HeapAlloc(GetProcessHeap(), 0, n);
     if (!This->info.LocalName)
     {
+        CloseHandle(This->mutex);
         HeapFree(GetProcessHeap(), 0, This->info.RemoteName);
         HeapFree(GetProcessHeap(), 0, This);
         return E_OUTOFMEMORY;
diff --git a/dlls/qmgr/qmgr.h b/dlls/qmgr/qmgr.h
index f3e22d3..b89bacc 100644
--- a/dlls/qmgr/qmgr.h
+++ b/dlls/qmgr/qmgr.h
@@ -72,6 +72,7 @@ typedef struct
     LONG ref;
     BG_FILE_INFO info;
     BG_FILE_PROGRESS fileProgress;
+    HANDLE mutex;
     struct list entryFromJob;
 } BackgroundCopyFileImpl;
 



More information about the wine-patches mailing list