Janitorial Projects > COM objects

Joris Huizer jorishuizer at planet.nl
Thu Sep 23 15:44:37 CDT 2004


Hello,

Just to get started, I thought I could do some work of the Interlocking
cleanup; The first patch wasn't applied yet so it's included in this 
patch as well

I tried to do as suggested in the patch on the site and came up with 
this; I hope it's usefull...

regards,

Joris


-------------- next part --------------
Index: dlls/ole32/antimoniker.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/antimoniker.c,v
retrieving revision 1.21
diff -u -r1.21 antimoniker.c
--- dlls/ole32/antimoniker.c	9 Sep 2004 21:03:58 -0000	1.21
+++ dlls/ole32/antimoniker.c	23 Sep 2004 20:35:17 -0000
@@ -186,7 +186,7 @@
 
     TRACE("(%p)\n",This);
 
-    return ++(This->ref);
+    return InterlockedIncrement(&This->ref);
 }
 
 /******************************************************************************
@@ -195,19 +195,21 @@
 ULONG WINAPI AntiMonikerImpl_Release(IMoniker* iface)
 {
     AntiMonikerImpl *This = (AntiMonikerImpl *)iface;
+    ULONG ref;
 
     TRACE("(%p)\n",This);
 
-    This->ref--;
+    ref = InterlockedDecrement(&This->ref);
+    
 
     /* destroy the object if there's no more reference on it */
-    if (This->ref==0){
+    if (ref == 0){
 
         AntiMonikerImpl_Destroy(This);
 
         return 0;
     }
-    return This->ref;
+    return ref;
 }
 
 /******************************************************************************
Index: dlls/ole32/bindctx.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/bindctx.c,v
retrieving revision 1.28
diff -u -r1.28 bindctx.c
--- dlls/ole32/bindctx.c	9 Sep 2004 21:03:58 -0000	1.28
+++ dlls/ole32/bindctx.c	23 Sep 2004 20:35:17 -0000
@@ -142,7 +142,7 @@
 
     TRACE("(%p)\n",This);
 
-    return ++(This->ref);
+    return InterlockedIncrement(&This->ref);
 }
 
 /******************************************************************************
@@ -151,12 +151,13 @@
 ULONG WINAPI BindCtxImpl_Release(IBindCtx* iface)
 {
     BindCtxImpl *This = (BindCtxImpl *)iface;
+    ULONG ref;
 
     TRACE("(%p)\n",This);
 
-    This->ref--;
+    ref = InterlockedDecrement(&This->ref);
 
-    if (This->ref==0){
+    if (ref == 0){
 
         /* release all registered objects */
         BindCtxImpl_ReleaseBoundObjects((IBindCtx*)This);
@@ -165,7 +166,7 @@
 
         return 0;
     }
-    return This->ref;
+    return ref;
 }
 
 
Index: dlls/ole32/clipboard.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/clipboard.c,v
retrieving revision 1.34
diff -u -r1.34 clipboard.c
--- dlls/ole32/clipboard.c	9 Sep 2004 21:03:58 -0000	1.34
+++ dlls/ole32/clipboard.c	23 Sep 2004 20:35:19 -0000
@@ -1162,9 +1162,8 @@
 
   TRACE("(%p)->(count=%lu)\n",This, This->ref);
 
-  This->ref++;
+  return InterlockedIncrement(&This->ref);
 
-  return This->ref;
 }
 
 /************************************************************************
@@ -1179,23 +1178,24 @@
    * Declare "This" pointer
    */
   OLEClipbrd *This = (OLEClipbrd *)iface;
+  ULONG ref;
 
   TRACE("(%p)->(count=%lu)\n",This, This->ref);
 
   /*
    * Decrease the reference count on this object.
    */
-  This->ref--;
+  ref = InterlockedDecrement(&This->ref);
 
   /*
    * If the reference count goes down to 0, perform suicide.
    */
-  if (This->ref==0)
+  if (ref == 0)
   {
     OLEClipbrd_Destroy(This);
   }
 
-  return This->ref;
+  return ref;
 }
 
 
@@ -1651,7 +1651,7 @@
   if (This->pUnkDataObj)
     IUnknown_AddRef(This->pUnkDataObj);
 
-  return ++(This->ref);
+  return InterlockedIncrement(&This->ref);
 }
 
 /************************************************************************
@@ -1663,13 +1663,15 @@
 {
   IEnumFORMATETCImpl *This = (IEnumFORMATETCImpl *)iface;
   LPMALLOC pIMalloc;
+  ULONG ref;
 
   TRACE("(%p)->(count=%lu)\n",This, This->ref);
 
   if (This->pUnkDataObj)
     IUnknown_Release(This->pUnkDataObj);  /* Release parent data object */
 
-  if (!--(This->ref))
+  ref = InterlockedDecrement(&This->ref);
+  if (!ref)
   {
     TRACE("() - destroying IEnumFORMATETC(%p)\n",This);
     if (SUCCEEDED(CoGetMalloc(MEMCTX_TASK, &pIMalloc)))
@@ -1682,7 +1684,7 @@
     return 0;
   }
 
-  return This->ref;
+  return ref;
 }
 
 /************************************************************************
Index: dlls/ole32/compositemoniker.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/compositemoniker.c,v
retrieving revision 1.31
diff -u -r1.31 compositemoniker.c
--- dlls/ole32/compositemoniker.c	9 Sep 2004 21:03:58 -0000	1.31
+++ dlls/ole32/compositemoniker.c	23 Sep 2004 20:35:20 -0000
@@ -243,7 +243,7 @@
 
     TRACE("(%p)\n",This);
 
-    return ++(This->ref);
+    return InterlockedIncrement(&This->ref);
 }
 
 /******************************************************************************
@@ -253,13 +253,14 @@
 {
     CompositeMonikerImpl *This = (CompositeMonikerImpl *)iface;
     ULONG i;
+    ULONG ref;
 
     TRACE("(%p)\n",This);
 
-    This->ref--;
+    ref = InterlockedDecrement(&This->ref);
 
     /* destroy the object if there's no more reference on it */
-    if (This->ref==0){
+    if (ref == 0){
 
         /* release all the components before destroying this object */
         for (i=0;i<This->tabLastIndex;i++)
@@ -269,7 +270,7 @@
 
         return 0;
     }
-    return This->ref;
+    return ref;
 }
 
 /******************************************************************************
@@ -1527,7 +1528,7 @@
 
     TRACE("(%p)\n",This);
 
-    return ++(This->ref);
+    return InterlockedIncrement(&This->ref);
 
 }
 
@@ -1537,14 +1538,14 @@
 ULONG   WINAPI EnumMonikerImpl_Release(IEnumMoniker* iface)
 {
     EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
-    ULONG i
-        ;
+    ULONG i;
+    ULONG ref;
     TRACE("(%p)\n",This);
 
-    This->ref--;
+    ref = InterlockedDecrement(&This->ref);
 
     /* destroy the object if there's no more reference on it */
-    if (This->ref==0){
+    if (ref == 0) {
 
         for(i=0;i<This->tabSize;i++)
             IMoniker_Release(This->tabMoniker[i]);
@@ -1554,7 +1555,7 @@
 
         return 0;
     }
-    return This->ref;
+    return ref;
 }
 
 /******************************************************************************
Index: dlls/ole32/datacache.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/datacache.c,v
retrieving revision 1.26
diff -u -r1.26 datacache.c
--- dlls/ole32/datacache.c	23 Aug 2004 19:39:50 -0000	1.26
+++ dlls/ole32/datacache.c	23 Sep 2004 20:35:21 -0000
@@ -968,10 +968,11 @@
             IUnknown*      iface)
 {
   _ICOM_THIS_From_NDIUnknown(DataCache, iface);
+  ULONG ref;
 
-  this->ref++;
+  ref = InterlockedIncrement(&this->ref);
 
-  return this->ref;
+  return ref;
 }
 
 /************************************************************************
@@ -986,23 +987,24 @@
             IUnknown*      iface)
 {
   _ICOM_THIS_From_NDIUnknown(DataCache, iface);
+  ULONG ref;
 
   /*
    * Decrease the reference count on this object.
    */
-  this->ref--;
+  ref = InterlockedDecrement(&this->ref);
 
   /*
    * If the reference count goes down to 0, perform suicide.
    */
-  if (this->ref==0)
+  if (ref == 0)
   {
     DataCache_Destroy(this);
 
     return 0;
   }
 
-  return this->ref;
+  return ref;
 }
 
 /*********************************************************
Index: dlls/ole32/defaulthandler.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/defaulthandler.c,v
retrieving revision 1.19
diff -u -r1.19 defaulthandler.c
--- dlls/ole32/defaulthandler.c	23 Aug 2004 19:39:50 -0000	1.19
+++ dlls/ole32/defaulthandler.c	23 Sep 2004 20:35:22 -0000
@@ -656,10 +656,11 @@
             IUnknown*      iface)
 {
   _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface);
+  ULONG ref;
 
-  this->ref++;
+  ref = InterlockedIncrement(&this->ref);
 
-  return this->ref;
+  return ref;
 }
 
 /************************************************************************
@@ -674,23 +675,24 @@
             IUnknown*      iface)
 {
   _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface);
+  ULONG ref;
 
   /*
    * Decrease the reference count on this object.
    */
-  this->ref--;
+  ref = InterlockedDecrement(&this->ref);
 
   /*
    * If the reference count goes down to 0, perform suicide.
    */
-  if (this->ref==0)
+  if (ref == 0)
   {
     DefaultHandler_Destroy(this);
 
     return 0;
   }
 
-  return this->ref;
+  return ref;
 }
 
 /*********************************************************
Index: dlls/ole32/filemoniker.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/filemoniker.c,v
retrieving revision 1.38
diff -u -r1.38 filemoniker.c
--- dlls/ole32/filemoniker.c	9 Sep 2004 21:03:58 -0000	1.38
+++ dlls/ole32/filemoniker.c	23 Sep 2004 20:35:23 -0000
@@ -194,7 +194,7 @@
 
     TRACE("(%p)\n",iface);
 
-    return ++(This->ref);
+    return InterlockedIncrement(&This->ref);
 }
 
 /******************************************************************************
@@ -203,19 +203,20 @@
 ULONG WINAPI FileMonikerImpl_Release(IMoniker* iface)
 {
     FileMonikerImpl *This = (FileMonikerImpl *)iface;
+    ULONG ref;
 
     TRACE("(%p)\n",iface);
 
-    This->ref--;
+    ref = InterlockedDecrement(&This->ref);
 
     /* destroy the object if there's no more reference on it */
-    if (This->ref==0){
+    if (ref == 0) {
 
         FileMonikerImpl_Destroy(This);
 
         return 0;
     }
-    return This->ref;
+    return ref;
 }
 
 /******************************************************************************
Index: dlls/ole32/hglobalstream.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/hglobalstream.c,v
retrieving revision 1.25
diff -u -r1.25 hglobalstream.c
--- dlls/ole32/hglobalstream.c	23 Aug 2004 19:39:50 -0000	1.25
+++ dlls/ole32/hglobalstream.c	23 Sep 2004 20:35:24 -0000
@@ -378,10 +378,11 @@
 		IStream* iface)
 {
   HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
+  ULONG ref;
 
-  This->ref++;
+  ref = InterlockedIncrement(&This->ref);
 
-  return This->ref;
+  return ref;
 }
 
 /***
@@ -392,12 +393,9 @@
 		IStream* iface)
 {
   HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
-
   ULONG newRef;
 
-  This->ref--;
-
-  newRef = This->ref;
+  newRef = InterlockedDecrement(&This->ref);
 
   /*
    * If the reference count goes down to 0, perform suicide.
Index: dlls/ole32/itemmoniker.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/itemmoniker.c,v
retrieving revision 1.28
diff -u -r1.28 itemmoniker.c
--- dlls/ole32/itemmoniker.c	9 Sep 2004 21:03:58 -0000	1.28
+++ dlls/ole32/itemmoniker.c	23 Sep 2004 20:35:25 -0000
@@ -193,7 +193,7 @@
 
     TRACE("(%p)\n",This);
 
-    return ++(This->ref);
+    return InterlockedIncrement(&This->ref);
 }
 
 /******************************************************************************
@@ -202,19 +202,20 @@
 ULONG WINAPI ItemMonikerImpl_Release(IMoniker* iface)
 {
     ItemMonikerImpl *This = (ItemMonikerImpl *)iface;
+    ULONG ref;
 
     TRACE("(%p)\n",This);
 
-    This->ref--;
+    ref = InterlockedDecrement(&This->ref);
 
     /* destroy the object if there's no more reference on it */
-    if (This->ref==0){
+    if (ref == 0){
 
         ItemMonikerImpl_Destroy(This);
 
         return 0;
     }
-    return This->ref;
+    return ref;
 }
 
 /******************************************************************************
Index: dlls/ole32/marshal.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/marshal.c,v
retrieving revision 1.31
diff -u -r1.31 marshal.c
--- dlls/ole32/marshal.c	9 Sep 2004 21:03:58 -0000	1.31
+++ dlls/ole32/marshal.c	23 Sep 2004 20:35:25 -0000
@@ -217,17 +217,20 @@
 static ULONG WINAPI
 StdMarshalImpl_AddRef(LPMARSHAL iface) {
   StdMarshalImpl *This = (StdMarshalImpl *)iface;
-  This->ref++;
-  return This->ref;
+  ULONG ref;
+  ref = InterlockedIncrement(&This->ref);
+  return ref;
 }
 
 static ULONG WINAPI
 StdMarshalImpl_Release(LPMARSHAL iface) {
   StdMarshalImpl *This = (StdMarshalImpl *)iface;
-  This->ref--;
+  ULONG ref;
+  ref = InterlockedDecrement(&This->ref);
 
-  if (This->ref)
-    return This->ref;
+  /* why is this syntax so different ?? */
+  if (ref)
+    return ref;
   HeapFree(GetProcessHeap(),0,This);
   return 0;
 }
Index: dlls/ole32/memlockbytes.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/memlockbytes.c,v
retrieving revision 1.20
diff -u -r1.20 memlockbytes.c
--- dlls/ole32/memlockbytes.c	23 Aug 2004 19:39:50 -0000	1.20
+++ dlls/ole32/memlockbytes.c	23 Sep 2004 20:35:25 -0000
@@ -351,10 +351,11 @@
 ULONG WINAPI HGLOBALLockBytesImpl_AddRef(ILockBytes* iface)
 {
   HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
+  ULONG ref;
 
-  This->ref++;
+  ref = InterlockedIncrement(&This->ref);
 
-  return This->ref;
+  return ref;
 }
 
 /******************************************************************************
@@ -365,21 +366,19 @@
 {
   HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
 
-  ULONG newRef;
+  ULONG ref;
 
-  This->ref--;
-
-  newRef = This->ref;
+  ref = InterlockedDecrement(&This->ref);
 
   /*
    * If the reference count goes down to 0, perform suicide.
    */
-  if (newRef==0)
+  if (ref==0)
   {
     HGLOBALLockBytesImpl_Destroy(This);
   }
 
-  return newRef;
+  return ref;
 }
 
 /******************************************************************************
Index: dlls/ole32/memlockbytes16.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/memlockbytes16.c,v
retrieving revision 1.8
diff -u -r1.8 memlockbytes16.c
--- dlls/ole32/memlockbytes16.c	12 Aug 2004 23:00:55 -0000	1.8
+++ dlls/ole32/memlockbytes16.c	23 Sep 2004 20:35:26 -0000
@@ -277,12 +277,13 @@
 ULONG WINAPI HGLOBALLockBytesImpl16_AddRef(ILockBytes16* iface)
 {
   HGLOBALLockBytesImpl16* const This=(HGLOBALLockBytesImpl16*)iface;
+  ULONG ref;
 
   TRACE("(%p)\n",This);
 
-  This->ref++;
+  ref = InterlockedIncrement(&This->ref);
 
-  return This->ref;
+  return ref;
 }
 
 /******************************************************************************
@@ -293,19 +294,17 @@
 {
   HGLOBALLockBytesImpl16* const This=(HGLOBALLockBytesImpl16*)iface;
 
-  ULONG newRef;
+  ULONG ref;
   TRACE("(%p)\n",This);
 
-  This->ref--;
-
-  newRef = This->ref;
+  ref = InterlockedDecrement(&This->ref);
 
   /*
    * If the reference count goes down to 0, perform suicide.
    */
-  if (newRef==0)
+  if (ref==0)
     HGLOBALLockBytesImpl16_Destroy(This);
-  return newRef;
+  return ref;
 }
 
 /******************************************************************************
Index: dlls/ole32/moniker.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/moniker.c,v
retrieving revision 1.35
diff -u -r1.35 moniker.c
--- dlls/ole32/moniker.c	9 Sep 2004 21:03:58 -0000	1.35
+++ dlls/ole32/moniker.c	23 Sep 2004 20:35:26 -0000
@@ -145,7 +145,7 @@
 
     TRACE("(%p)\n",This);
 
-    return ++(This->ref);
+    return InterlockedIncrement(&This->ref);
 }
 
 /***********************************************************************
@@ -174,13 +174,14 @@
 {
     DWORD i;
     RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface;
+    ULONG ref;
 
     TRACE("(%p)\n",This);
 
-    This->ref--;
+    ref = InterlockedDecrement(&This->ref);
 
     /* unitialize ROT structure if there's no more reference to it*/
-    if (This->ref==0){
+    if (ref == 0) {
 
         /* release all registered objects */
         for(i=0;i<This->runObjTabLastIndx;i++)
@@ -201,7 +202,7 @@
         return 0;
     }
 
-    return This->ref;
+    return ref;
 }
 
 /***********************************************************************
Index: dlls/ole32/oleobj.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/oleobj.c,v
retrieving revision 1.18
diff -u -r1.18 oleobj.c
--- dlls/ole32/oleobj.c	9 Sep 2004 21:03:58 -0000	1.18
+++ dlls/ole32/oleobj.c	23 Sep 2004 20:35:27 -0000
@@ -189,17 +189,18 @@
   LPOLEADVISEHOLDER iface)
 {
   OleAdviseHolderImpl *This = (OleAdviseHolderImpl *)iface;
+  ULONG ref;
   TRACE("(%p)->(ref=%ld)\n", This, This->ref);
-  This->ref--;
+  ref = InterlockedDecrement(&This->ref);
 
-  if (This->ref == 0)
+  if (ref == 0)
   {
     OleAdviseHolderImpl_Destructor(This);
 
     return 0;
   }
 
-  return This->ref;
+  return ref;
 }
 
 /******************************************************************************
@@ -523,10 +524,12 @@
   IDataAdviseHolder*      iface)
 {
   DataAdviseHolder *This = (DataAdviseHolder *)iface;
+  ULONG ref;
+  
   TRACE("(%p) (ref=%ld)\n", This, This->ref);
-  This->ref++;
+  ref = InterlockedIncrement(&This->ref);
 
-  return This->ref;
+  return ref;
 }
 
 /************************************************************************
@@ -538,24 +541,25 @@
   IDataAdviseHolder*      iface)
 {
   DataAdviseHolder *This = (DataAdviseHolder *)iface;
+  ULONG ref;
   TRACE("(%p) (ref=%ld)\n", This, This->ref);
 
   /*
    * Decrease the reference count on this object.
    */
-  This->ref--;
+  ref = InterlockedDecrement(&This->ref);
 
   /*
    * If the reference count goes down to 0, perform suicide.
    */
-  if (This->ref==0)
+  if (ref==0)
   {
     DataAdviseHolder_Destructor(This);
 
     return 0;
   }
 
-  return This->ref;
+  return ref;
 }
 
 /************************************************************************
Index: dlls/ole32/oleproxy.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/oleproxy.c,v
retrieving revision 1.21
diff -u -r1.21 oleproxy.c
--- dlls/ole32/oleproxy.c	9 Sep 2004 21:03:58 -0000	1.21
+++ dlls/ole32/oleproxy.c	23 Sep 2004 20:35:27 -0000
@@ -103,18 +103,20 @@
 static ULONG WINAPI
 CFStub_AddRef(LPRPCSTUBBUFFER iface) {
     CFStub *This = (CFStub *)iface;
+    ULONG ref;
 
-    This->ref++;
-    return This->ref;
+    ref = InterlockedIncrement(&This->ref);
+    return ref;
 }
 
 static ULONG WINAPI
 CFStub_Release(LPRPCSTUBBUFFER iface) {
     CFStub *This = (CFStub *)iface;
+    ULONG ref;
 
-    This->ref--;
-    if (This->ref)
-	return This->ref;
+    ref = InterlockedDecrement(&This->ref);
+    if (ref)
+	return ref;
     HeapFree(GetProcessHeap(),0,This);
     return 0;
 }
@@ -286,18 +288,19 @@
 
 static ULONG WINAPI IRpcProxyBufferImpl_AddRef(LPRPCPROXYBUFFER iface) {
     ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
-    return ++(This->ref);
+    return InterlockedIncrement(&This->ref);
 }
 
 static ULONG WINAPI IRpcProxyBufferImpl_Release(LPRPCPROXYBUFFER iface) {
     ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
+    ULONG ref = InterlockedDecrement(&This->ref);
 
-    if (!--(This->ref)) {
+    if (!ref) {
 	IRpcChannelBuffer_Release(This->chanbuf);This->chanbuf = NULL;
 	HeapFree(GetProcessHeap(),0,This);
 	return 0;
     }
-    return This->ref;
+    return ref;
 }
 
 static HRESULT WINAPI IRpcProxyBufferImpl_Connect(LPRPCPROXYBUFFER iface,IRpcChannelBuffer* pRpcChannelBuffer) {
@@ -330,16 +333,19 @@
 }
 
 static ULONG   WINAPI CFProxy_AddRef(LPCLASSFACTORY iface) {
+    ULONG ref;
     ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
-    This->ref++;
-    return This->ref;
+    ref = InterlockedIncrement(&This->ref);
+    return ref;
 }
 
 static ULONG   WINAPI CFProxy_Release(LPCLASSFACTORY iface) {
+    ULONG ref;
     ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
-    This->ref--;
-    if (This->ref)
-	return This->ref;
+    
+    ref = InterlockedDecrement(&This->ref);
+    if (ref)
+	return ref;
     HeapFree(GetProcessHeap(),0,This);
     return 0;
 }
Index: dlls/ole32/rpc.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/rpc.c,v
retrieving revision 1.26
diff -u -r1.26 rpc.c
--- dlls/ole32/rpc.c	9 Sep 2004 21:03:58 -0000	1.26
+++ dlls/ole32/rpc.c	23 Sep 2004 20:35:28 -0000
@@ -286,20 +286,22 @@
 static ULONG WINAPI
 PipeBuf_AddRef(LPRPCCHANNELBUFFER iface) {
     PipeBuf *This = (PipeBuf *)iface;
-    This->ref++;
-    return This->ref;
+    ULONG ref;
+    ref = InterlockedIncrement(&This->ref);
+    return ref;
 }
 
 static ULONG WINAPI
 PipeBuf_Release(LPRPCCHANNELBUFFER iface) {
     PipeBuf *This = (PipeBuf *)iface;
+    ULONG ref;
     wine_rpc_disconnect_header header;
     HANDLE pipe;
     DWORD reqtype = REQTYPE_DISCONNECT;
 
-    This->ref--;
-    if (This->ref)
-	return This->ref;
+    ref = InterlockedDecrement(&This->ref);
+    if (ref)
+	return ref;
 
     FIXME("Free all stuff\n");
 
Index: dlls/ole32/stg_stream.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/stg_stream.c,v
retrieving revision 1.21
diff -u -r1.21 stg_stream.c
--- dlls/ole32/stg_stream.c	23 Aug 2004 19:39:50 -0000	1.21
+++ dlls/ole32/stg_stream.c	23 Sep 2004 20:35:28 -0000
@@ -222,9 +222,10 @@
 {
   StgStreamImpl* const This=(StgStreamImpl*)iface;
 
-  This->ref++;
+  ULONG ref;
+  ref = InterlockedIncrement(&This->ref);
 
-  return This->ref;
+  return ref;
 }
 
 /***
@@ -236,21 +237,19 @@
 {
   StgStreamImpl* const This=(StgStreamImpl*)iface;
 
-  ULONG newRef;
+  ULONG ref;
 
-  This->ref--;
-
-  newRef = This->ref;
+  ref = InterlockedDecrement(&This->ref);
 
   /*
    * If the reference count goes down to 0, perform suicide.
    */
-  if (newRef==0)
+  if (ref==0)
   {
     StgStreamImpl_Destroy(This);
   }
 
-  return newRef;
+  return ref;
 }
 
 /***
Index: dlls/ole32/storage.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/storage.c,v
retrieving revision 1.42
diff -u -r1.42 storage.c
--- dlls/ole32/storage.c	22 Sep 2004 02:46:40 -0000	1.42
+++ dlls/ole32/storage.c	23 Sep 2004 20:35:29 -0000
@@ -986,7 +986,7 @@
  */
 ULONG WINAPI IStream16_fnAddRef(IStream16* iface) {
 	IStream16Impl *This = (IStream16Impl *)iface;
-	return ++(This->ref);
+	return InterlockedIncrement(&This->ref);
 }
 
 /******************************************************************************
@@ -994,15 +994,16 @@
  */
 ULONG WINAPI IStream16_fnRelease(IStream16* iface) {
 	IStream16Impl *This = (IStream16Impl *)iface;
+        ULONG ref;
 	FlushFileBuffers(This->hf);
-	This->ref--;
-	if (!This->ref) {
+        ref = InterlockedDecrement(&This->ref);
+	if (!ref) {
 		CloseHandle(This->hf);
                 UnMapLS( This->thisptr );
 		HeapFree( GetProcessHeap(), 0, This );
 		return 0;
 	}
-	return This->ref;
+	return ref;
 }
 
 /******************************************************************************
@@ -1480,7 +1481,7 @@
  */
 ULONG WINAPI IStream_fnAddRef(IStream* iface) {
 	IStream32Impl *This = (IStream32Impl *)iface;
-	return ++(This->ref);
+	return InterlockedIncrement(&This->ref);
 }
 
 /******************************************************************************
@@ -1488,14 +1489,15 @@
  */
 ULONG WINAPI IStream_fnRelease(IStream* iface) {
 	IStream32Impl *This = (IStream32Impl *)iface;
+        ULONG ref;
 	FlushFileBuffers(This->hf);
-	This->ref--;
-	if (!This->ref) {
+        ref = InterlockedDecrement(&This->ref);
+	if (!ref) {
 		CloseHandle(This->hf);
 		HeapFree( GetProcessHeap(), 0, This );
 		return 0;
 	}
-	return This->ref;
+	return ref;
 }
 
 /* --- IStorage16 implementation */
@@ -1534,7 +1536,7 @@
  */
 ULONG WINAPI IStorage16_fnAddRef(IStorage16* iface) {
 	IStorage16Impl *This = (IStorage16Impl *)iface;
-	return ++(This->ref);
+	return InterlockedIncrement(&This->ref);
 }
 
 /******************************************************************************
@@ -1542,9 +1544,10 @@
  */
 ULONG WINAPI IStorage16_fnRelease(IStorage16* iface) {
 	IStorage16Impl *This = (IStorage16Impl *)iface;
-	This->ref--;
-	if (This->ref)
-		return This->ref;
+	ULONG ref;
+        ref = InterlockedDecrement(&This->ref);
+	if (ref)
+		return ref;
         UnMapLS( This->thisptr );
         HeapFree( GetProcessHeap(), 0, This );
 	return 0;
Index: dlls/ole32/storage32.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/storage32.c,v
retrieving revision 1.59
diff -u -r1.59 storage32.c
--- dlls/ole32/storage32.c	22 Sep 2004 02:46:40 -0000	1.59
+++ dlls/ole32/storage32.c	23 Sep 2004 20:35:34 -0000
@@ -291,9 +291,9 @@
             IStorage* iface)
 {
   StorageBaseImpl *This = (StorageBaseImpl *)iface;
-  This->ref++;
+  ULONG ref = InterlockedIncrement(&This->ref);
 
-  return This->ref;
+  return ref; 
 }
 
 /************************************************************************
@@ -311,12 +311,12 @@
   /*
    * Decrease the reference count on this object.
    */
-  This->ref--;
+  ULONG ref = InterlockedDecrement(&This->ref);
 
   /*
    * If the reference count goes down to 0, perform suicide.
    */
-  if (This->ref==0)
+  if (ref == 0)
   {
     /*
      * Since we are using a system of base-classes, we want to call the
@@ -328,7 +328,7 @@
     return 0;
   }
 
-  return This->ref;
+  return ref;
 }
 
 /************************************************************************
@@ -3638,8 +3638,8 @@
 {
   IEnumSTATSTGImpl* const This=(IEnumSTATSTGImpl*)iface;
 
-  This->ref++;
-  return This->ref;
+  ULONG ref = InterlockedIncrement(&This->ref);
+  return ref;
 }
 
 ULONG   WINAPI IEnumSTATSTGImpl_Release(
@@ -3649,8 +3649,7 @@
 
   ULONG newRef;
 
-  This->ref--;
-  newRef = This->ref;
+  newRef = InterlockedDecrement(&This->ref);
 
   /*
    * If the reference count goes down to 0, perform suicide.
Index: dlls/oleaut32/connpt.c
===================================================================
RCS file: /home/wine/wine/dlls/oleaut32/connpt.c,v
retrieving revision 1.12
diff -u -r1.12 connpt.c
--- dlls/oleaut32/connpt.c	9 Sep 2004 21:03:58 -0000	1.12
+++ dlls/oleaut32/connpt.c	23 Sep 2004 20:35:34 -0000
@@ -193,10 +193,11 @@
 static ULONG WINAPI ConnectionPointImpl_AddRef(IConnectionPoint* iface)
 {
   ConnectionPointImpl *This = (ConnectionPointImpl *)iface;
+  ULONG ref;
   TRACE("(%p)->(ref=%ld)\n", This, This->ref);
-  This->ref++;
+  ref = InterlockedIncrement(&This->ref);
 
-  return This->ref;
+  return ref;
 }
 
 /************************************************************************
@@ -208,24 +209,25 @@
       IConnectionPoint* iface)
 {
   ConnectionPointImpl *This = (ConnectionPointImpl *)iface;
+  ULONG ref;
   TRACE("(%p)->(ref=%ld)\n", This, This->ref);
 
   /*
    * Decrease the reference count on this object.
    */
-  This->ref--;
+  ref = InterlockedDecrement(&This->ref);
 
   /*
    * If the reference count goes down to 0, perform suicide.
    */
-  if (This->ref==0)
+  if (ref == 0)
   {
     ConnectionPointImpl_Destroy(This);
 
     return 0;
   }
 
-  return This->ref;
+  return ref;
 }
 
 /************************************************************************
@@ -473,10 +475,11 @@
 static ULONG WINAPI EnumConnectionsImpl_AddRef(IEnumConnections* iface)
 {
   EnumConnectionsImpl *This = (EnumConnectionsImpl *)iface;
+  ULONG ref;
   TRACE("(%p)->(ref=%ld)\n", This, This->ref);
-  This->ref++;
+  ref = InterlockedIncrement(&This->ref);
   IUnknown_AddRef(This->pUnk);
-  return This->ref;
+  return ref;
 }
 
 /************************************************************************
@@ -487,6 +490,7 @@
 static ULONG WINAPI EnumConnectionsImpl_Release(IEnumConnections* iface)
 {
   EnumConnectionsImpl *This = (EnumConnectionsImpl *)iface;
+  ULONG ref;
   TRACE("(%p)->(ref=%ld)\n", This, This->ref);
 
   IUnknown_Release(This->pUnk);
@@ -494,19 +498,19 @@
   /*
    * Decrease the reference count on this object.
    */
-  This->ref--;
+  ref = InterlockedDecrement(&This->ref);
 
   /*
    * If the reference count goes down to 0, perform suicide.
    */
-  if (This->ref==0)
+  if (ref == 0)
   {
     EnumConnectionsImpl_Destroy(This);
 
     return 0;
   }
 
-  return This->ref;
+  return ref;
 }
 
 /************************************************************************
Index: dlls/oleaut32/dispatch.c
===================================================================
RCS file: /home/wine/wine/dlls/oleaut32/dispatch.c,v
retrieving revision 1.20
diff -u -r1.20 dispatch.c
--- dlls/oleaut32/dispatch.c	9 Sep 2004 21:03:58 -0000	1.20
+++ dlls/oleaut32/dispatch.c	23 Sep 2004 20:35:35 -0000
@@ -278,7 +278,7 @@
     StdDispatch *This = (StdDispatch *)iface;
     TRACE("()\n");
 
-    return ++This->ref;
+    return InterlockedIncrement(&This->ref);
 }
 
 /******************************************************************************
@@ -289,18 +289,18 @@
 static ULONG WINAPI StdDispatch_Release(LPDISPATCH iface)
 {
     StdDispatch *This = (StdDispatch *)iface;
-    ULONG ret;
+    ULONG ref;
     TRACE("(%p)->()\n", This);
 
-    ret = This->ref--;
+    ref = InterlockedDecrement(&This->ref);
 
-    if (This->ref == 0)
+    if (ref == 0)
     {
         ITypeInfo_Release(This->pTypeInfo);
         CoTaskMemFree(This);
     }
 
-    return ret;
+    return ref;
 }
 
 /******************************************************************************
Index: dlls/urlmon/umon.c
===================================================================
RCS file: /home/wine/wine/dlls/urlmon/umon.c,v
retrieving revision 1.41
diff -u -r1.41 umon.c
--- dlls/urlmon/umon.c	22 Sep 2004 02:46:39 -0000	1.41
+++ dlls/urlmon/umon.c	23 Sep 2004 20:35:36 -0000
@@ -197,7 +197,7 @@
 
     TRACE("(%p)\n",This);
 
-    return ++(This->ref);
+    return InterlockedIncrement(&This->ref);
 }
 
 /******************************************************************************
@@ -206,19 +206,20 @@
 static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface)
 {
     URLMonikerImpl *This = (URLMonikerImpl *)iface;
+    ULONG ref;
 
     TRACE("(%p)\n",This);
 
-    This->ref--;
+    ref = InterlockedDecrement(&This->ref);
 
     /* destroy the object if there's no more reference on it */
-    if (This->ref==0){
+    if (ref == 0){
 
         URLMonikerImpl_Destroy(This);
 
         return 0;
     }
-    return This->ref;
+    return ref;
 }
 
 /******************************************************************************


More information about the wine-patches mailing list