Commit 34cffce6 authored by Joris Huizer's avatar Joris Huizer Committed by Alexandre Julliard

Ref count increment/decrement cleanup.

parent 0c3f2868
......@@ -186,7 +186,7 @@ ULONG WINAPI AntiMonikerImpl_AddRef(IMoniker* iface)
TRACE("(%p)\n",This);
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
/******************************************************************************
......@@ -195,19 +195,16 @@ ULONG WINAPI AntiMonikerImpl_AddRef(IMoniker* iface)
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);
AntiMonikerImpl_Destroy(This);
return 0;
}
return This->ref;
return ref;
}
/******************************************************************************
......
......@@ -142,7 +142,7 @@ ULONG WINAPI BindCtxImpl_AddRef(IBindCtx* iface)
TRACE("(%p)\n",This);
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
/******************************************************************************
......@@ -151,21 +151,19 @@ ULONG WINAPI BindCtxImpl_AddRef(IBindCtx* iface)
ULONG WINAPI BindCtxImpl_Release(IBindCtx* iface)
{
BindCtxImpl *This = (BindCtxImpl *)iface;
ULONG ref;
TRACE("(%p)\n",This);
This->ref--;
if (This->ref==0){
ref = InterlockedDecrement(&This->ref);
if (ref == 0){
/* release all registered objects */
BindCtxImpl_ReleaseBoundObjects((IBindCtx*)This);
BindCtxImpl_Destroy(This);
return 0;
}
return This->ref;
return ref;
}
......
......@@ -1162,9 +1162,8 @@ static ULONG WINAPI OLEClipbrd_IDataObject_AddRef(
TRACE("(%p)->(count=%lu)\n",This, This->ref);
This->ref++;
return InterlockedIncrement(&This->ref);
return This->ref;
}
/************************************************************************
......@@ -1179,23 +1178,24 @@ static ULONG WINAPI OLEClipbrd_IDataObject_Release(
* 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 @@ static ULONG WINAPI OLEClipbrd_IEnumFORMATETC_AddRef(LPENUMFORMATETC iface)
if (This->pUnkDataObj)
IUnknown_AddRef(This->pUnkDataObj);
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
/************************************************************************
......@@ -1663,13 +1663,15 @@ static ULONG WINAPI OLEClipbrd_IEnumFORMATETC_Release(LPENUMFORMATETC iface)
{
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)))
......@@ -1679,10 +1681,8 @@ static ULONG WINAPI OLEClipbrd_IEnumFORMATETC_Release(LPENUMFORMATETC iface)
}
HeapFree(GetProcessHeap(),0,This);
return 0;
}
return This->ref;
return ref;
}
/************************************************************************
......
......@@ -243,7 +243,7 @@ ULONG WINAPI CompositeMonikerImpl_AddRef(IMoniker* iface)
TRACE("(%p)\n",This);
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
/******************************************************************************
......@@ -253,23 +253,22 @@ ULONG WINAPI CompositeMonikerImpl_Release(IMoniker* iface)
{
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++)
IMoniker_Release(This->tabMoniker[i]);
CompositeMonikerImpl_Destroy(This);
return 0;
}
return This->ref;
return ref;
}
/******************************************************************************
......@@ -1527,7 +1526,7 @@ ULONG WINAPI EnumMonikerImpl_AddRef(IEnumMoniker* iface)
TRACE("(%p)\n",This);
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
......@@ -1537,24 +1536,22 @@ ULONG WINAPI EnumMonikerImpl_AddRef(IEnumMoniker* iface)
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]);
HeapFree(GetProcessHeap(),0,This->tabMoniker);
HeapFree(GetProcessHeap(),0,This);
return 0;
}
return This->ref;
return ref;
}
/******************************************************************************
......
......@@ -134,12 +134,12 @@ typedef struct DataCache DataCache;
* There is a version to accomodate all of the VTables implemented
* by this object.
*/
#define _ICOM_THIS_From_IDataObject(class,name) class* this = (class*)name;
#define _ICOM_THIS_From_NDIUnknown(class, name) class* this = (class*)(((char*)name)-sizeof(void*));
#define _ICOM_THIS_From_IPersistStorage(class, name) class* this = (class*)(((char*)name)-2*sizeof(void*));
#define _ICOM_THIS_From_IViewObject2(class, name) class* this = (class*)(((char*)name)-3*sizeof(void*));
#define _ICOM_THIS_From_IOleCache2(class, name) class* this = (class*)(((char*)name)-4*sizeof(void*));
#define _ICOM_THIS_From_IOleCacheControl(class, name) class* this = (class*)(((char*)name)-5*sizeof(void*));
#define _ICOM_THIS_From_IDataObject(class,name) class* this = (class*)name
#define _ICOM_THIS_From_NDIUnknown(class, name) class* this = (class*)(((char*)name)-sizeof(void*))
#define _ICOM_THIS_From_IPersistStorage(class, name) class* this = (class*)(((char*)name)-2*sizeof(void*))
#define _ICOM_THIS_From_IViewObject2(class, name) class* this = (class*)(((char*)name)-3*sizeof(void*))
#define _ICOM_THIS_From_IOleCache2(class, name) class* this = (class*)(((char*)name)-4*sizeof(void*))
#define _ICOM_THIS_From_IOleCacheControl(class, name) class* this = (class*)(((char*)name)-5*sizeof(void*))
/*
* Prototypes for the methods of the DataCache class.
......@@ -968,10 +968,7 @@ static ULONG WINAPI DataCache_NDIUnknown_AddRef(
IUnknown* iface)
{
_ICOM_THIS_From_NDIUnknown(DataCache, iface);
this->ref++;
return this->ref;
return InterlockedIncrement(&this->ref);
}
/************************************************************************
......@@ -986,23 +983,19 @@ static ULONG WINAPI DataCache_NDIUnknown_Release(
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)
{
DataCache_Destroy(this);
return 0;
}
if (ref == 0) DataCache_Destroy(this);
return this->ref;
return ref;
}
/*********************************************************
......
......@@ -126,10 +126,10 @@ typedef struct DefaultHandler DefaultHandler;
* There is a version to accomodate all of the VTables implemented
* by this object.
*/
#define _ICOM_THIS_From_IOleObject(class,name) class* this = (class*)name;
#define _ICOM_THIS_From_NDIUnknown(class, name) class* this = (class*)(((char*)name)-sizeof(void*));
#define _ICOM_THIS_From_IDataObject(class, name) class* this = (class*)(((char*)name)-2*sizeof(void*));
#define _ICOM_THIS_From_IRunnableObject(class, name) class* this = (class*)(((char*)name)-3*sizeof(void*));
#define _ICOM_THIS_From_IOleObject(class,name) class* this = (class*)name
#define _ICOM_THIS_From_NDIUnknown(class, name) class* this = (class*)(((char*)name)-sizeof(void*))
#define _ICOM_THIS_From_IDataObject(class, name) class* this = (class*)(((char*)name)-2*sizeof(void*))
#define _ICOM_THIS_From_IRunnableObject(class, name) class* this = (class*)(((char*)name)-3*sizeof(void*))
/*
* Prototypes for the methods of the DefaultHandler class.
......@@ -656,10 +656,7 @@ static ULONG WINAPI DefaultHandler_NDIUnknown_AddRef(
IUnknown* iface)
{
_ICOM_THIS_From_NDIUnknown(DefaultHandler, iface);
this->ref++;
return this->ref;
return InterlockedIncrement(&this->ref);
}
/************************************************************************
......@@ -674,23 +671,19 @@ static ULONG WINAPI DefaultHandler_NDIUnknown_Release(
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)
{
DefaultHandler_Destroy(this);
return 0;
}
if (ref == 0) DefaultHandler_Destroy(this);
return this->ref;
return ref;
}
/*********************************************************
......
......@@ -194,7 +194,7 @@ ULONG WINAPI FileMonikerImpl_AddRef(IMoniker* iface)
TRACE("(%p)\n",iface);
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
/******************************************************************************
......@@ -203,19 +203,16 @@ ULONG WINAPI FileMonikerImpl_AddRef(IMoniker* iface)
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);
FileMonikerImpl_Destroy(This);
return 0;
}
return This->ref;
return ref;
}
/******************************************************************************
......
......@@ -378,10 +378,7 @@ ULONG WINAPI HGLOBALStreamImpl_AddRef(
IStream* iface)
{
HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
This->ref++;
return This->ref;
return InterlockedIncrement(&This->ref);
}
/***
......@@ -392,12 +389,9 @@ ULONG WINAPI HGLOBALStreamImpl_Release(
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.
......
......@@ -193,7 +193,7 @@ ULONG WINAPI ItemMonikerImpl_AddRef(IMoniker* iface)
TRACE("(%p)\n",This);
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
/******************************************************************************
......@@ -202,19 +202,16 @@ ULONG WINAPI ItemMonikerImpl_AddRef(IMoniker* iface)
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);
ItemMonikerImpl_Destroy(This);
return 0;
}
return This->ref;
return ref;
}
/******************************************************************************
......
......@@ -217,19 +217,16 @@ StdMarshalImpl_QueryInterface(LPMARSHAL iface,REFIID riid,LPVOID *ppv) {
static ULONG WINAPI
StdMarshalImpl_AddRef(LPMARSHAL iface) {
StdMarshalImpl *This = (StdMarshalImpl *)iface;
This->ref++;
return This->ref;
return InterlockedIncrement(&This->ref);
}
static ULONG WINAPI
StdMarshalImpl_Release(LPMARSHAL iface) {
StdMarshalImpl *This = (StdMarshalImpl *)iface;
This->ref--;
ULONG ref = InterlockedDecrement(&This->ref);
if (This->ref)
return This->ref;
HeapFree(GetProcessHeap(),0,This);
return 0;
if (!ref) HeapFree(GetProcessHeap(),0,This);
return ref;
}
static HRESULT WINAPI
......
......@@ -351,10 +351,7 @@ HRESULT WINAPI HGLOBALLockBytesImpl_QueryInterface(
ULONG WINAPI HGLOBALLockBytesImpl_AddRef(ILockBytes* iface)
{
HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
This->ref++;
return This->ref;
return InterlockedIncrement(&This->ref);
}
/******************************************************************************
......@@ -364,22 +361,19 @@ ULONG WINAPI HGLOBALLockBytesImpl_AddRef(ILockBytes* iface)
ULONG WINAPI HGLOBALLockBytesImpl_Release(ILockBytes* iface)
{
HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
ULONG ref;
ULONG newRef;
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;
}
/******************************************************************************
......
......@@ -280,9 +280,7 @@ ULONG WINAPI HGLOBALLockBytesImpl16_AddRef(ILockBytes16* iface)
TRACE("(%p)\n",This);
This->ref++;
return This->ref;
return InterlockedIncrement(&This->ref);
}
/******************************************************************************
......@@ -292,20 +290,18 @@ ULONG WINAPI HGLOBALLockBytesImpl16_AddRef(ILockBytes16* iface)
ULONG WINAPI HGLOBALLockBytesImpl16_Release(ILockBytes16* iface)
{
HGLOBALLockBytesImpl16* const This=(HGLOBALLockBytesImpl16*)iface;
ULONG ref;
ULONG newRef;
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;
}
/******************************************************************************
......
......@@ -145,7 +145,7 @@ ULONG WINAPI RunningObjectTableImpl_AddRef(IRunningObjectTable* iface)
TRACE("(%p)\n",This);
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
/***********************************************************************
......@@ -174,13 +174,14 @@ ULONG WINAPI RunningObjectTableImpl_Release(IRunningObjectTable* iface)
{
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++)
......@@ -197,11 +198,9 @@ ULONG WINAPI RunningObjectTableImpl_Release(IRunningObjectTable* iface)
/* there's no more elements in the table */
This->runObjTabRegister=0;
This->runObjTabLastIndx=0;
return 0;
}
return This->ref;
return ref;
}
/***********************************************************************
......
......@@ -189,17 +189,13 @@ static ULONG WINAPI OleAdviseHolderImpl_Release(
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)
{
OleAdviseHolderImpl_Destructor(This);
return 0;
}
if (ref == 0) OleAdviseHolderImpl_Destructor(This);
return This->ref;
return ref;
}
/******************************************************************************
......@@ -524,9 +520,7 @@ static ULONG WINAPI DataAdviseHolder_AddRef(
{
DataAdviseHolder *This = (DataAdviseHolder *)iface;
TRACE("(%p) (ref=%ld)\n", This, This->ref);
This->ref++;
return This->ref;
return InterlockedIncrement(&This->ref);
}
/************************************************************************
......@@ -538,24 +532,20 @@ static ULONG WINAPI DataAdviseHolder_Release(
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)
{
DataAdviseHolder_Destructor(This);
return 0;
}
if (ref==0) DataAdviseHolder_Destructor(This);
return This->ref;
return ref;
}
/************************************************************************
......
......@@ -103,20 +103,17 @@ CFStub_QueryInterface(LPRPCSTUBBUFFER iface, REFIID riid, LPVOID *ppv) {
static ULONG WINAPI
CFStub_AddRef(LPRPCSTUBBUFFER iface) {
CFStub *This = (CFStub *)iface;
This->ref++;
return This->ref;
return InterlockedIncrement(&This->ref);
}
static ULONG WINAPI
CFStub_Release(LPRPCSTUBBUFFER iface) {
CFStub *This = (CFStub *)iface;
ULONG ref;
This->ref--;
if (This->ref)
return This->ref;
HeapFree(GetProcessHeap(),0,This);
return 0;
ref = InterlockedDecrement(&This->ref);
if (!ref) HeapFree(GetProcessHeap(),0,This);
return ref;
}
static HRESULT WINAPI
......@@ -286,18 +283,18 @@ static HRESULT WINAPI IRpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface,
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) {
......@@ -331,17 +328,16 @@ CFProxy_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVOID *ppv) {
static ULONG WINAPI CFProxy_AddRef(LPCLASSFACTORY iface) {
ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
This->ref++;
return This->ref;
return InterlockedIncrement(&This->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;
HeapFree(GetProcessHeap(),0,This);
return 0;
ref = InterlockedDecrement(&This->ref);
if (!ref) HeapFree(GetProcessHeap(),0,This);
return ref;
}
static HRESULT WINAPI CFProxy_CreateInstance(
......
......@@ -286,20 +286,20 @@ PipeBuf_QueryInterface(
static ULONG WINAPI
PipeBuf_AddRef(LPRPCCHANNELBUFFER iface) {
PipeBuf *This = (PipeBuf *)iface;
This->ref++;
return This->ref;
return InterlockedIncrement(&This->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");
......
......@@ -221,10 +221,7 @@ ULONG WINAPI StgStreamImpl_AddRef(
IStream* iface)
{
StgStreamImpl* const This=(StgStreamImpl*)iface;
This->ref++;
return This->ref;
return InterlockedIncrement(&This->ref);
}
/***
......@@ -236,21 +233,19 @@ ULONG WINAPI StgStreamImpl_Release(
{
StgStreamImpl* const This=(StgStreamImpl*)iface;
ULONG newRef;
This->ref--;
ULONG 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;
}
/***
......
......@@ -986,7 +986,7 @@ HRESULT WINAPI IStream16_fnQueryInterface(
*/
ULONG WINAPI IStream16_fnAddRef(IStream16* iface) {
IStream16Impl *This = (IStream16Impl *)iface;
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
/******************************************************************************
......@@ -994,15 +994,15 @@ ULONG WINAPI IStream16_fnAddRef(IStream16* iface) {
*/
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 +1480,7 @@ HRESULT WINAPI IStream_fnQueryInterface(
*/
ULONG WINAPI IStream_fnAddRef(IStream* iface) {
IStream32Impl *This = (IStream32Impl *)iface;
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
/******************************************************************************
......@@ -1488,14 +1488,14 @@ ULONG WINAPI IStream_fnAddRef(IStream* iface) {
*/
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 +1534,7 @@ HRESULT WINAPI IStorage16_fnQueryInterface(
*/
ULONG WINAPI IStorage16_fnAddRef(IStorage16* iface) {
IStorage16Impl *This = (IStorage16Impl *)iface;
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
/******************************************************************************
......@@ -1542,12 +1542,14 @@ ULONG WINAPI IStorage16_fnAddRef(IStorage16* iface) {
*/
ULONG WINAPI IStorage16_fnRelease(IStorage16* iface) {
IStorage16Impl *This = (IStorage16Impl *)iface;
This->ref--;
if (This->ref)
return This->ref;
UnMapLS( This->thisptr );
HeapFree( GetProcessHeap(), 0, This );
return 0;
ULONG ref;
ref = InterlockedDecrement(&This->ref);
if (!ref)
{
UnMapLS( This->thisptr );
HeapFree( GetProcessHeap(), 0, This );
}
return ref;
}
/******************************************************************************
......
......@@ -291,9 +291,7 @@ ULONG WINAPI StorageBaseImpl_AddRef(
IStorage* iface)
{
StorageBaseImpl *This = (StorageBaseImpl *)iface;
This->ref++;
return This->ref;
return InterlockedIncrement(&This->ref);
}
/************************************************************************
......@@ -311,12 +309,12 @@ ULONG WINAPI StorageBaseImpl_Release(
/*
* 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
......@@ -324,11 +322,9 @@ ULONG WINAPI StorageBaseImpl_Release(
* using virtual functions to implement the destructor.
*/
This->v_destructor(This);
return 0;
}
return This->ref;
return ref;
}
/************************************************************************
......@@ -3637,9 +3633,7 @@ ULONG WINAPI IEnumSTATSTGImpl_AddRef(
IEnumSTATSTG* iface)
{
IEnumSTATSTGImpl* const This=(IEnumSTATSTGImpl*)iface;
This->ref++;
return This->ref;
return InterlockedIncrement(&This->ref);
}
ULONG WINAPI IEnumSTATSTGImpl_Release(
......@@ -3649,8 +3643,7 @@ ULONG WINAPI IEnumSTATSTGImpl_Release(
ULONG newRef;
This->ref--;
newRef = This->ref;
newRef = InterlockedDecrement(&This->ref);
/*
* If the reference count goes down to 0, perform suicide.
......
......@@ -194,9 +194,7 @@ static ULONG WINAPI ConnectionPointImpl_AddRef(IConnectionPoint* iface)
{
ConnectionPointImpl *This = (ConnectionPointImpl *)iface;
TRACE("(%p)->(ref=%ld)\n", This, This->ref);
This->ref++;
return This->ref;
return InterlockedIncrement(&This->ref);
}
/************************************************************************
......@@ -208,24 +206,20 @@ static ULONG WINAPI ConnectionPointImpl_Release(
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)
{
ConnectionPointImpl_Destroy(This);
return 0;
}
if (ref == 0) ConnectionPointImpl_Destroy(This);
return This->ref;
return ref;
}
/************************************************************************
......@@ -473,10 +467,11 @@ static HRESULT WINAPI EnumConnectionsImpl_QueryInterface(
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 +482,7 @@ static ULONG WINAPI EnumConnectionsImpl_AddRef(IEnumConnections* iface)
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 +490,14 @@ static ULONG WINAPI EnumConnectionsImpl_Release(IEnumConnections* iface)
/*
* 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)
{
EnumConnectionsImpl_Destroy(This);
return 0;
}
if (ref == 0) EnumConnectionsImpl_Destroy(This);
return This->ref;
return ref;
}
/************************************************************************
......
......@@ -278,7 +278,7 @@ static ULONG WINAPI StdDispatch_AddRef(LPDISPATCH iface)
StdDispatch *This = (StdDispatch *)iface;
TRACE("()\n");
return ++This->ref;
return InterlockedIncrement(&This->ref);
}
/******************************************************************************
......@@ -289,18 +289,18 @@ static ULONG WINAPI StdDispatch_AddRef(LPDISPATCH iface)
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;
}
/******************************************************************************
......
......@@ -197,7 +197,7 @@ static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface)
TRACE("(%p)\n",This);
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
/******************************************************************************
......@@ -206,19 +206,16 @@ static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface)
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);
URLMonikerImpl_Destroy(This);
return 0;
}
return This->ref;
return ref;
}
/******************************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment