From 202b340a51da82272d53ecbbf40af82d54e07798 Mon Sep 17 00:00:00 2001 From: Paul Vriens Date: Sun, 9 Jan 2005 17:29:21 +0000 Subject: [PATCH] - use Interlocked* functions in AddRef and Release. - store the result of the Interlocked functions and use only this. --- dlls/ddraw/d3ddevice/main.c | 16 ++++++++++----- dlls/ddraw/d3ddevice/mesa.c | 8 +++++--- dlls/ddraw/d3dexecutebuffer.c | 16 ++++++++++----- dlls/ddraw/d3dlight.c | 24 ++++++++++++++-------- dlls/ddraw/d3dmaterial.c | 16 ++++++++++----- dlls/ddraw/d3dvertexbuffer.c | 16 ++++++++++----- dlls/ddraw/d3dviewport.c | 16 ++++++++++----- dlls/ddraw/dclipper/main.c | 17 ++++++++++------ dlls/ddraw/ddraw/main.c | 11 ++++++----- dlls/ddraw/dpalette/main.c | 15 +++++++++----- dlls/ddraw/dsurface/main.c | 22 +++++++++++---------- dlls/ddraw/main.c | 5 +++-- dlls/ole32/errorinfo.c | 14 +++++++------ dlls/ole32/ifs.c | 12 ++++++----- dlls/ole32/oleobj.c | 7 +++++-- dlls/oleaut32/tests/safearray.c | 4 ++-- dlls/oleaut32/typelib.c | 35 ++++++++++++++++----------------- dlls/oleaut32/typelib2.c | 28 +++++++++++++------------- 18 files changed, 171 insertions(+), 111 deletions(-) diff --git a/dlls/ddraw/d3ddevice/main.c b/dlls/ddraw/d3ddevice/main.c index 646fa14d7db..4e81d38b81b 100644 --- a/dlls/ddraw/d3ddevice/main.c +++ b/dlls/ddraw/d3ddevice/main.c @@ -260,16 +260,22 @@ ULONG WINAPI Main_IDirect3DDeviceImpl_7_3T_2T_1T_AddRef(LPDIRECT3DDEVICE7 iface) { ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface); - TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref); - return ++(This->ref); + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, ref - 1); + + return ref; } ULONG WINAPI Main_IDirect3DDeviceImpl_7_3T_2T_1T_Release(LPDIRECT3DDEVICE7 iface) { ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface); - TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref); - if (!--(This->ref)) { + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1); + + if (!ref) { int i; /* Release texture associated with the device */ for (i = 0; i < MAX_TEXTURES; i++) { @@ -280,7 +286,7 @@ Main_IDirect3DDeviceImpl_7_3T_2T_1T_Release(LPDIRECT3DDEVICE7 iface) HeapFree(GetProcessHeap(), 0, This); return 0; } - return This->ref; + return ref; } HRESULT WINAPI diff --git a/dlls/ddraw/d3ddevice/mesa.c b/dlls/ddraw/d3ddevice/mesa.c index bfaada8a792..bc4c43fafa4 100644 --- a/dlls/ddraw/d3ddevice/mesa.c +++ b/dlls/ddraw/d3ddevice/mesa.c @@ -381,9 +381,11 @@ GL_IDirect3DDeviceImpl_7_3T_2T_1T_Release(LPDIRECT3DDEVICE7 iface) { ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface); IDirect3DDeviceGLImpl *glThis = (IDirect3DDeviceGLImpl *) This; + ULONG ref = InterlockedDecrement(&This->ref); - TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref); - if (!--(This->ref)) { + TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1); + + if (!ref) { int i; IDirectDrawSurfaceImpl *surface = This->surface, *surf; @@ -442,7 +444,7 @@ GL_IDirect3DDeviceImpl_7_3T_2T_1T_Release(LPDIRECT3DDEVICE7 iface) HeapFree(GetProcessHeap(), 0, This); return 0; } - return This->ref; + return ref; } HRESULT WINAPI diff --git a/dlls/ddraw/d3dexecutebuffer.c b/dlls/ddraw/d3dexecutebuffer.c index 909ee6a2b24..ad83685c7e8 100644 --- a/dlls/ddraw/d3dexecutebuffer.c +++ b/dlls/ddraw/d3dexecutebuffer.c @@ -519,16 +519,22 @@ ULONG WINAPI Main_IDirect3DExecuteBufferImpl_1_AddRef(LPDIRECT3DEXECUTEBUFFER iface) { ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface); - FIXME("(%p/%p)->()incrementing from %lu.\n", This, iface, This->ref ); - return ++(This->ref); + ULONG ref = InterlockedIncrement(&This->ref); + + FIXME("(%p/%p)->()incrementing from %lu.\n", This, iface, ref - 1); + + return ref; } ULONG WINAPI Main_IDirect3DExecuteBufferImpl_1_Release(LPDIRECT3DEXECUTEBUFFER iface) { ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface); - TRACE("(%p/%p)->()decrementing from %lu.\n", This, iface, This->ref); - if (!--(This->ref)) { + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p/%p)->()decrementing from %lu.\n", This, iface, ref + 1); + + if (!ref) { if ((This->desc.lpData != NULL) && This->need_free) HeapFree(GetProcessHeap(),0,This->desc.lpData); HeapFree(GetProcessHeap(),0,This->vertex_data); @@ -537,7 +543,7 @@ Main_IDirect3DExecuteBufferImpl_1_Release(LPDIRECT3DEXECUTEBUFFER iface) return 0; } - return This->ref; + return ref; } HRESULT WINAPI diff --git a/dlls/ddraw/d3dlight.c b/dlls/ddraw/d3dlight.c index 801444d3693..174a1b61bc3 100644 --- a/dlls/ddraw/d3dlight.c +++ b/dlls/ddraw/d3dlight.c @@ -53,20 +53,26 @@ ULONG WINAPI Main_IDirect3DLightImpl_1_AddRef(LPDIRECT3DLIGHT iface) { ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface); - TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref); - return ++(This->ref); + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, ref - 1); + + return ref; } ULONG WINAPI Main_IDirect3DLightImpl_1_Release(LPDIRECT3DLIGHT iface) { ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface); - TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref); - if (!--(This->ref)) { + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1); + + if (!ref) { HeapFree(GetProcessHeap(), 0, This); return 0; } - return This->ref; + return ref; } HRESULT WINAPI @@ -191,14 +197,16 @@ GL_IDirect3DLightImpl_1_Release(LPDIRECT3DLIGHT iface) { ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface); IDirect3DLightGLImpl *glThis = (IDirect3DLightGLImpl *) This; + ULONG ref = InterlockedDecrement(&This->ref); - TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref); - if (!--(This->ref)) { + TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1); + + if (!ref) { ((IDirect3DGLImpl *) This->d3d->d3d_private)->light_released(This->d3d, glThis->light_num); HeapFree(GetProcessHeap(), 0, This); return 0; } - return This->ref; + return ref; } #if !defined(__STRICT_ANSI__) && defined(__GNUC__) diff --git a/dlls/ddraw/d3dmaterial.c b/dlls/ddraw/d3dmaterial.c index 3b39f02f133..8216794c723 100644 --- a/dlls/ddraw/d3dmaterial.c +++ b/dlls/ddraw/d3dmaterial.c @@ -85,20 +85,26 @@ ULONG WINAPI Main_IDirect3DMaterialImpl_3_2T_1T_AddRef(LPDIRECT3DMATERIAL3 iface) { ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface); - TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref); - return ++(This->ref); + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, ref - 1); + + return ref; } ULONG WINAPI Main_IDirect3DMaterialImpl_3_2T_1T_Release(LPDIRECT3DMATERIAL3 iface) { ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface); - TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref); - if (!--(This->ref)) { + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1); + + if (!ref) { HeapFree(GetProcessHeap(), 0, This); return 0; } - return This->ref; + return ref; } HRESULT WINAPI diff --git a/dlls/ddraw/d3dvertexbuffer.c b/dlls/ddraw/d3dvertexbuffer.c index ca8d7321014..7775b871e5d 100644 --- a/dlls/ddraw/d3dvertexbuffer.c +++ b/dlls/ddraw/d3dvertexbuffer.c @@ -73,21 +73,27 @@ ULONG WINAPI Main_IDirect3DVertexBufferImpl_7_1T_AddRef(LPDIRECT3DVERTEXBUFFER7 iface) { ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface); - TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref); - return ++(This->ref); + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, ref - 1); + + return ref; } ULONG WINAPI Main_IDirect3DVertexBufferImpl_7_1T_Release(LPDIRECT3DVERTEXBUFFER7 iface) { ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface); - TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref); - if (--(This->ref) == 0) { + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1); + + if (ref == 0) { HeapFree(GetProcessHeap(), 0, This->vertices); HeapFree(GetProcessHeap(), 0, This); return 0; } - return This->ref; + return ref; } HRESULT WINAPI diff --git a/dlls/ddraw/d3dviewport.c b/dlls/ddraw/d3dviewport.c index 0daadb25a0f..12fd1a2a161 100644 --- a/dlls/ddraw/d3dviewport.c +++ b/dlls/ddraw/d3dviewport.c @@ -126,20 +126,26 @@ ULONG WINAPI Main_IDirect3DViewportImpl_3_2_1_AddRef(LPDIRECT3DVIEWPORT3 iface) { ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface); - TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref); - return ++(This->ref); + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, ref - 1); + + return ref; } ULONG WINAPI Main_IDirect3DViewportImpl_3_2_1_Release(LPDIRECT3DVIEWPORT3 iface) { ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface); - TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref); - if (!--(This->ref)) { + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1); + + if (!ref) { HeapFree(GetProcessHeap(), 0, This); return 0; } - return This->ref; + return ref; } diff --git a/dlls/ddraw/dclipper/main.c b/dlls/ddraw/dclipper/main.c index 0195ea2e446..a0f69d7933f 100644 --- a/dlls/ddraw/dclipper/main.c +++ b/dlls/ddraw/dclipper/main.c @@ -114,14 +114,16 @@ void Main_DirectDrawClipper_ForceDestroy(IDirectDrawClipperImpl* This) ULONG WINAPI Main_DirectDrawClipper_Release(LPDIRECTDRAWCLIPPER iface) { IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface; - TRACE("(%p)->() decrementing from %lu.\n", This, This->ref ); + ULONG ref = InterlockedDecrement(&This->ref); - if (--This->ref == 0) + TRACE("(%p)->() decrementing from %lu.\n", This, ref + 1); + + if (ref == 0) { Main_DirectDrawClipper_Destroy(This); return 0; } - else return This->ref; + else return ref; } /*********************************************************************** @@ -211,7 +213,7 @@ HRESULT WINAPI Main_DirectDrawClipper_QueryInterface( || IsEqualGUID(&IID_IDirectDrawClipper, riid)) { *ppvObj = ICOM_INTERFACE(This, IDirectDrawClipper); - ++This->ref; + InterlockedIncrement(&This->ref); return S_OK; } else @@ -223,8 +225,11 @@ HRESULT WINAPI Main_DirectDrawClipper_QueryInterface( ULONG WINAPI Main_DirectDrawClipper_AddRef( LPDIRECTDRAWCLIPPER iface ) { IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface; - TRACE("(%p)->() incrementing from %lu.\n", This, This->ref ); - return ++This->ref; + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p)->() incrementing from %lu.\n", This, ref - 1); + + return ref; } HRESULT WINAPI Main_DirectDrawClipper_GetHWnd( diff --git a/dlls/ddraw/ddraw/main.c b/dlls/ddraw/ddraw/main.c index 6e0feeebd6c..a2f47f59d3d 100644 --- a/dlls/ddraw/ddraw/main.c +++ b/dlls/ddraw/ddraw/main.c @@ -149,17 +149,18 @@ void Main_DirectDraw_final_release(IDirectDrawImpl* This) ULONG WINAPI Main_DirectDraw_AddRef(LPDIRECTDRAW7 iface) { IDirectDrawImpl *This = (IDirectDrawImpl *)iface; - TRACE("(%p)->() incrementing from %lu.\n", This, This->ref ); + ULONG ref = InterlockedIncrement(&This->ref); - return ++This->ref; + TRACE("(%p)->() incrementing from %lu.\n", This, ref -1); + + return ref; } ULONG WINAPI Main_DirectDraw_Release(LPDIRECTDRAW7 iface) { - ULONG ref; IDirectDrawImpl *This = (IDirectDrawImpl *)iface; - TRACE("(%p)->() decrementing from %lu.\n", This, This->ref ); + ULONG ref = InterlockedDecrement(&This->ref); - ref = --This->ref; + TRACE("(%p)->() decrementing from %lu.\n", This, ref +1); if (ref == 0) { diff --git a/dlls/ddraw/dpalette/main.c b/dlls/ddraw/dpalette/main.c index 532837835da..9e955e71e52 100644 --- a/dlls/ddraw/dpalette/main.c +++ b/dlls/ddraw/dpalette/main.c @@ -208,21 +208,26 @@ ULONG WINAPI Main_DirectDrawPalette_Release(LPDIRECTDRAWPALETTE iface) { IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface; - TRACE("(%p)->() decrementing from %lu.\n", This, This->ref ); + ULONG ref = InterlockedDecrement(&This->ref); - if (!--This->ref) + TRACE("(%p)->() decrementing from %lu.\n", This, ref + 1); + + if (!ref) { Main_DirectDrawPalette_Destroy(This); return 0; } - return This->ref; + return ref; } ULONG WINAPI Main_DirectDrawPalette_AddRef(LPDIRECTDRAWPALETTE iface) { IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface; - TRACE("(%p)->() incrementing from %lu.\n", This, This->ref ); - return ++This->ref; + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p)->() incrementing from %lu.\n", This, ref - 1); + + return ref; } HRESULT WINAPI diff --git a/dlls/ddraw/dsurface/main.c b/dlls/ddraw/dsurface/main.c index 7b982cbdfd4..b7aa27d505c 100644 --- a/dlls/ddraw/dsurface/main.c +++ b/dlls/ddraw/dsurface/main.c @@ -125,10 +125,11 @@ void Main_DirectDrawSurface_ForceDestroy(IDirectDrawSurfaceImpl* This) ULONG WINAPI Main_DirectDrawSurface_Release(LPDIRECTDRAWSURFACE7 iface) { IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + ULONG ref = InterlockedDecrement(&This->ref); - TRACE("(%p)->(): decreasing from %ld\n", This, This->ref); + TRACE("(%p)->(): decreasing from %ld\n", This, ref + 1); - if (--This->ref == 0) + if (ref == 0) { if (This->aux_release) This->aux_release(This->aux_ctx, This->aux_data); @@ -139,16 +140,17 @@ ULONG WINAPI Main_DirectDrawSurface_Release(LPDIRECTDRAWSURFACE7 iface) return 0; } - return This->ref; + return ref; } ULONG WINAPI Main_DirectDrawSurface_AddRef(LPDIRECTDRAWSURFACE7 iface) { IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface; + ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p)->(): increasing from %ld\n", This, This->ref); + TRACE("(%p)->(): increasing from %ld\n", This, ref - 1); - return ++This->ref; + return ref; } HRESULT WINAPI @@ -164,7 +166,7 @@ Main_DirectDrawSurface_QueryInterface(LPDIRECTDRAWSURFACE7 iface, REFIID riid, || IsEqualGUID(&IID_IDirectDrawSurface7, riid) || IsEqualGUID(&IID_IDirectDrawSurface4, riid)) { - This->ref++; + InterlockedIncrement(&This->ref); *ppObj = ICOM_INTERFACE(This, IDirectDrawSurface7); return S_OK; } @@ -172,13 +174,13 @@ Main_DirectDrawSurface_QueryInterface(LPDIRECTDRAWSURFACE7 iface, REFIID riid, || IsEqualGUID(&IID_IDirectDrawSurface2, riid) || IsEqualGUID(&IID_IDirectDrawSurface3, riid)) { - This->ref++; + InterlockedIncrement(&This->ref); *ppObj = ICOM_INTERFACE(This, IDirectDrawSurface3); return S_OK; } else if (IsEqualGUID(&IID_IDirectDrawGammaControl, riid)) { - This->ref++; + InterlockedIncrement(&This->ref); *ppObj = ICOM_INTERFACE(This, IDirectDrawGammaControl); return S_OK; } @@ -199,7 +201,7 @@ Main_DirectDrawSurface_QueryInterface(LPDIRECTDRAWSURFACE7 iface, REFIID riid, *ppObj = ICOM_INTERFACE(d3ddevimpl, IDirect3DDevice); TRACE(" returning Direct3DDevice interface at %p.\n", *ppObj); - This->ref++; /* No idea if this is correct.. Need to check using real Windows */ + InterlockedIncrement(&This->ref); /* No idea if this is correct.. Need to check using real Windows */ return ret_value; } else if (IsEqualGUID( &IID_IDirect3DTexture, riid ) || @@ -230,7 +232,7 @@ Main_DirectDrawSurface_QueryInterface(LPDIRECTDRAWSURFACE7 iface, REFIID riid, *ppObj = ICOM_INTERFACE(This, IDirect3DTexture2); TRACE(" returning Direct3DTexture2 interface at %p.\n", *ppObj); } - This->ref++; + InterlockedIncrement(&This->ref); return ret_value; } #endif diff --git a/dlls/ddraw/main.c b/dlls/ddraw/main.c index 5a38a463b25..c6ae4583404 100644 --- a/dlls/ddraw/main.c +++ b/dlls/ddraw/main.c @@ -496,10 +496,11 @@ DDCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) static ULONG WINAPI DDCF_AddRef(LPCLASSFACTORY iface) { IClassFactoryImpl *This = (IClassFactoryImpl *)iface; + ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p)->() incrementing from %ld.\n", This, This->ref); + TRACE("(%p)->() incrementing from %ld.\n", This, ref - 1); - return InterlockedIncrement(&This->ref); + return ref; } static ULONG WINAPI DDCF_Release(LPCLASSFACTORY iface) diff --git a/dlls/ole32/errorinfo.c b/dlls/ole32/errorinfo.c index ca46ac5b5ee..74f4caccc95 100644 --- a/dlls/ole32/errorinfo.c +++ b/dlls/ole32/errorinfo.c @@ -149,13 +149,13 @@ static ISupportErrorInfoVtbl ISupportErrorInfoImpl_VTable; converts a objectpointer to This */ #define _IErrorInfo_Offset ((int)(&(((ErrorInfoImpl*)0)->lpvtei))) -#define _ICOM_THIS_From_IErrorInfo(class, name) class* This = (class*)(((char*)name)-_IErrorInfo_Offset); +#define _ICOM_THIS_From_IErrorInfo(class, name) class* This = (class*)(((char*)name)-_IErrorInfo_Offset) #define _ICreateErrorInfo_Offset ((int)(&(((ErrorInfoImpl*)0)->lpvtcei))) -#define _ICOM_THIS_From_ICreateErrorInfo(class, name) class* This = (class*)(((char*)name)-_ICreateErrorInfo_Offset); +#define _ICOM_THIS_From_ICreateErrorInfo(class, name) class* This = (class*)(((char*)name)-_ICreateErrorInfo_Offset) #define _ISupportErrorInfo_Offset ((int)(&(((ErrorInfoImpl*)0)->lpvtsei))) -#define _ICOM_THIS_From_ISupportErrorInfo(class, name) class* This = (class*)(((char*)name)-_ISupportErrorInfo_Offset); +#define _ICOM_THIS_From_ISupportErrorInfo(class, name) class* This = (class*)(((char*)name)-_ISupportErrorInfo_Offset) /* converts This to a objectpointer @@ -227,15 +227,17 @@ static ULONG WINAPI IErrorInfoImpl_Release( IErrorInfo* iface) { _ICOM_THIS_From_IErrorInfo(ErrorInfoImpl, iface); - TRACE("(%p)->(count=%lu)\n",This,This->ref); + ULONG ref = InterlockedDecrement(&This->ref); - if (!InterlockedDecrement(&This->ref)) + TRACE("(%p)->(count=%lu)\n",This,ref+1); + + if (!ref) { TRACE("-- destroying IErrorInfo(%p)\n",This); HeapFree(GetProcessHeap(),0,This); return 0; } - return This->ref; + return ref; } static HRESULT WINAPI IErrorInfoImpl_GetGUID( diff --git a/dlls/ole32/ifs.c b/dlls/ole32/ifs.c index bb80208d952..0d505bddb4d 100644 --- a/dlls/ole32/ifs.c +++ b/dlls/ole32/ifs.c @@ -394,10 +394,11 @@ static ULONG WINAPI IMallocSpy_fnAddRef (LPMALLOCSPY iface) { _MallocSpy *This = (_MallocSpy *)iface; + ULONG ref = InterlockedIncrement(&This->ref); - TRACE ("(%p)->(count=%lu)\n", This, This->ref); + TRACE ("(%p)->(count=%lu)\n", This, ref - 1); - return ++(This->ref); + return ref; } /****************************************************************************** @@ -410,13 +411,14 @@ static ULONG WINAPI IMallocSpy_fnRelease (LPMALLOCSPY iface) { _MallocSpy *This = (_MallocSpy *)iface; + ULONG ref = InterlockedDecrement(&This->ref); - TRACE ("(%p)->(count=%lu)\n", This, This->ref); + TRACE ("(%p)->(count=%lu)\n", This, ref + 1); - if (!--(This->ref)) { + if (!ref) { /* our allocation list MUST be empty here */ } - return This->ref; + return ref; } static ULONG WINAPI IMallocSpy_fnPreAlloc(LPMALLOCSPY iface, ULONG cbRequest) diff --git a/dlls/ole32/oleobj.c b/dlls/ole32/oleobj.c index 45efbc0c528..370020feb97 100644 --- a/dlls/ole32/oleobj.c +++ b/dlls/ole32/oleobj.c @@ -181,8 +181,11 @@ static ULONG WINAPI OleAdviseHolderImpl_AddRef( LPOLEADVISEHOLDER iface) { OleAdviseHolderImpl *This = (OleAdviseHolderImpl *)iface; - TRACE("(%p)->(ref=%ld)\n", This, This->ref); - return ++(This->ref); + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p)->(ref=%ld)\n", This, ref - 1); + + return ref; } /****************************************************************************** diff --git a/dlls/oleaut32/tests/safearray.c b/dlls/oleaut32/tests/safearray.c index 08094f2f34f..1bfa894b70b 100644 --- a/dlls/oleaut32/tests/safearray.c +++ b/dlls/oleaut32/tests/safearray.c @@ -96,13 +96,13 @@ static IRecordInfoImpl *IRecordInfoImpl_Construct() static ULONG CALLBACK IRecordInfoImpl_AddRef(IRecordInfo *iface) { IRecordInfoImpl* This=(IRecordInfoImpl*)iface; - return ++This->ref; + return InterlockedIncrement(&This->ref); } static ULONG CALLBACK IRecordInfoImpl_Release(IRecordInfo *iface) { IRecordInfoImpl* This=(IRecordInfoImpl*)iface; - return --This->ref; + return InterlockedDecrement(&This->ref); } static BOOL fail_GetSize; /* Whether to fail the GetSize call */ diff --git a/dlls/oleaut32/typelib.c b/dlls/oleaut32/typelib.c index 713aa4432d1..e2bac391c03 100644 --- a/dlls/oleaut32/typelib.c +++ b/dlls/oleaut32/typelib.c @@ -847,7 +847,7 @@ typedef struct tagITypeLibImpl { ITypeLib2Vtbl *lpVtbl; ITypeCompVtbl *lpVtblTypeComp; - UINT ref; + ULONG ref; TLIBATTR LibAttr; /* guid,lcid,syskind,version,flags */ /* strings can be stored in tlb as multibyte strings BUT they are *always* @@ -958,7 +958,7 @@ typedef struct tagITypeInfoImpl { ITypeInfo2Vtbl *lpVtbl; ITypeCompVtbl *lpVtblTypeComp; - UINT ref; + ULONG ref; TYPEATTR TypeAttr ; /* _lots_ of type information. */ ITypeLibImpl * pTypeLib; /* back pointer to typelib */ int index; /* index in this typelib; */ @@ -1276,7 +1276,7 @@ static void dump_DispParms(DISPPARAMS * pdp) static void dump_TypeInfo(ITypeInfoImpl * pty) { - TRACE("%p ref=%u\n", pty, pty->ref); + TRACE("%p ref=%lu\n", pty, pty->ref); TRACE("attr:%s\n", debugstr_guid(&(pty->TypeAttr.guid))); TRACE("kind:%s\n", typekind_desc[pty->TypeAttr.typekind]); TRACE("fct:%u var:%u impl:%u\n", @@ -3434,10 +3434,11 @@ static HRESULT WINAPI ITypeLib2_fnQueryInterface( static ULONG WINAPI ITypeLib2_fnAddRef( ITypeLib2 *iface) { ITypeLibImpl *This = (ITypeLibImpl *)iface; + ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p)->ref was %u\n",This, This->ref); + TRACE("(%p)->ref was %lu\n",This, ref - 1); - return ++(This->ref); + return ref; } /* ITypeLib::Release @@ -3445,12 +3446,11 @@ static ULONG WINAPI ITypeLib2_fnAddRef( ITypeLib2 *iface) static ULONG WINAPI ITypeLib2_fnRelease( ITypeLib2 *iface) { ITypeLibImpl *This = (ITypeLibImpl *)iface; + ULONG ref = InterlockedDecrement(&This->ref); - --(This->ref); + TRACE("(%p)->(%lu)\n",This, ref); - TRACE("(%p)->(%u)\n",This, This->ref); - - if (!This->ref) + if (!ref) { /* remove cache entry */ TRACE("removing from cache list\n"); @@ -3493,7 +3493,7 @@ static ULONG WINAPI ITypeLib2_fnRelease( ITypeLib2 *iface) return 0; } - return This->ref; + return ref; } /* ITypeLib::GetTypeInfoCount @@ -4110,12 +4110,12 @@ static HRESULT WINAPI ITypeInfo_fnQueryInterface( static ULONG WINAPI ITypeInfo_fnAddRef( ITypeInfo2 *iface) { ITypeInfoImpl *This = (ITypeInfoImpl *)iface; + ULONG ref = InterlockedIncrement(&This->ref); - ++(This->ref); ITypeLib2_AddRef((ITypeLib2*)This->pTypeLib); - TRACE("(%p)->ref is %u\n",This, This->ref); - return This->ref; + TRACE("(%p)->ref is %lu\n",This, ref); + return ref; } /* ITypeInfo::Release @@ -4123,12 +4123,11 @@ static ULONG WINAPI ITypeInfo_fnAddRef( ITypeInfo2 *iface) static ULONG WINAPI ITypeInfo_fnRelease(ITypeInfo2 *iface) { ITypeInfoImpl *This = (ITypeInfoImpl *)iface; + ULONG ref = InterlockedDecrement(&This->ref); - --(This->ref); + TRACE("(%p)->(%lu)\n",This, ref); - TRACE("(%p)->(%u)\n",This, This->ref); - - if (This->ref) { + if (ref) { /* We don't release ITypeLib when ref=0 becouse it means that funtion is called by ITypeLi2_Release */ ITypeLib2_Release((ITypeLib2*)This->pTypeLib); @@ -4156,7 +4155,7 @@ static ULONG WINAPI ITypeInfo_fnRelease(ITypeInfo2 *iface) HeapFree(GetProcessHeap(),0,This); return 0; } - return This->ref; + return ref; } /* ITypeInfo::GetTypeAttr diff --git a/dlls/oleaut32/typelib2.c b/dlls/oleaut32/typelib2.c index f9c88d83cae..a51423f4c40 100644 --- a/dlls/oleaut32/typelib2.c +++ b/dlls/oleaut32/typelib2.c @@ -1142,10 +1142,11 @@ static HRESULT WINAPI ICreateTypeInfo2_fnQueryInterface( static ULONG WINAPI ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2 *iface) { ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface; + ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p)->ref was %u\n",This, This->ref); + TRACE("(%p)->ref was %lu\n",This, ref - 1); - return ++(This->ref); + return ref; } /****************************************************************************** @@ -1156,12 +1157,11 @@ static ULONG WINAPI ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2 *iface) static ULONG WINAPI ICreateTypeInfo2_fnRelease(ICreateTypeInfo2 *iface) { ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface; + ULONG ref = InterlockedDecrement(&This->ref); - --(This->ref); + TRACE("(%p)->(%lu)\n",This, ref); - TRACE("(%p)->(%u)\n",This, This->ref); - - if (!This->ref) { + if (!ref) { if (This->typelib) { ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)This->typelib); This->typelib = NULL; @@ -1172,7 +1172,7 @@ static ULONG WINAPI ICreateTypeInfo2_fnRelease(ICreateTypeInfo2 *iface) return 0; } - return This->ref; + return ref; } @@ -3009,10 +3009,11 @@ static HRESULT WINAPI ICreateTypeLib2_fnQueryInterface( static ULONG WINAPI ICreateTypeLib2_fnAddRef(ICreateTypeLib2 *iface) { ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface; + ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p)->ref was %u\n",This, This->ref); + TRACE("(%p)->ref was %lu\n",This, ref - 1); - return ++(This->ref); + return ref; } /****************************************************************************** @@ -3023,12 +3024,11 @@ static ULONG WINAPI ICreateTypeLib2_fnAddRef(ICreateTypeLib2 *iface) static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface) { ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface; + ULONG ref = InterlockedDecrement(&This->ref); - --(This->ref); + TRACE("(%p)->(%lu)\n",This, ref); - TRACE("(%p)->(%u)\n",This, This->ref); - - if (!This->ref) { + if (!ref) { int i; for (i = 0; i < MSFT_SEG_MAX; i++) { @@ -3050,7 +3050,7 @@ static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface) return 0; } - return This->ref; + return ref; }