Michael Stefaniuc : avifil32: Use atomic operations to manipulate the refcount.

Alexandre Julliard julliard at winehq.org
Fri Jul 15 09:07:04 CDT 2016


Module: wine
Branch: master
Commit: 72175acdd191773d4ec28cbe2e2300a6640192bc
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=72175acdd191773d4ec28cbe2e2300a6640192bc

Author: Michael Stefaniuc <mstefani at redhat.de>
Date:   Tue Jul 12 10:06:18 2016 +0200

avifil32: Use atomic operations to manipulate the refcount.

Signed-off-by: Michael Stefaniuc <mstefani at redhat.de>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/avifil32/factory.c | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/dlls/avifil32/factory.c b/dlls/avifil32/factory.c
index c74a716..aa0c44e 100644
--- a/dlls/avifil32/factory.c
+++ b/dlls/avifil32/factory.c
@@ -57,11 +57,9 @@ static const IClassFactoryVtbl iclassfact = {
 
 typedef struct
 {
-  /* IUnknown fields */
   IClassFactory IClassFactory_iface;
-  DWORD	 dwRef;
-
-  CLSID  clsid;
+  LONG ref;
+  CLSID clsid;
 } IClassFactoryImpl;
 
 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
@@ -82,7 +80,7 @@ static HRESULT AVIFILE_CreateClassFactory(const CLSID *pclsid, const IID *riid,
     return E_OUTOFMEMORY;
 
   pClassFactory->IClassFactory_iface.lpVtbl = &iclassfact;
-  pClassFactory->dwRef     = 0;
+  pClassFactory->ref = 0;
   pClassFactory->clsid     = *pclsid;
 
   hr = IClassFactory_QueryInterface(&pClassFactory->IClassFactory_iface, riid, ppv);
@@ -109,26 +107,26 @@ static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,
   return E_NOINTERFACE;
 }
 
-static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
+static ULONG WINAPI IClassFactory_fnAddRef(IClassFactory *iface)
 {
-  IClassFactoryImpl *This = impl_from_IClassFactory(iface);
+    IClassFactoryImpl *This = impl_from_IClassFactory(iface);
+    ULONG ref = InterlockedIncrement(&This->ref);
 
-  TRACE("(%p)\n", iface);
-
-  return ++(This->dwRef);
+    TRACE("(%p) ref = %u\n", This, ref);
+    return ref;
 }
 
-static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
+static ULONG WINAPI IClassFactory_fnRelease(IClassFactory *iface)
 {
-  IClassFactoryImpl *This = impl_from_IClassFactory(iface);
+    IClassFactoryImpl *This = impl_from_IClassFactory(iface);
+    ULONG ref = InterlockedDecrement(&This->ref);
 
-  TRACE("(%p)\n", iface);
-  if ((--(This->dwRef)) > 0)
-    return This->dwRef;
+    TRACE("(%p) ref = %u\n", This, ref);
 
-  HeapFree(GetProcessHeap(), 0, This);
+    if(!ref)
+        HeapFree(GetProcessHeap(), 0, This);
 
-  return 0;
+    return ref;
 }
 
 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,




More information about the wine-cvs mailing list