- use Interlocked* functions in AddRef and Release.

- store the result of the Interlocked functions and use only this.
This commit is contained in:
Paul Vriens 2005-01-10 12:25:29 +00:00 committed by Alexandre Julliard
parent b3f064ccc7
commit 545cdfa2ef
6 changed files with 57 additions and 33 deletions

View File

@ -36,7 +36,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(amstream);
typedef struct { typedef struct {
IAMMultiMediaStream lpVtbl; IAMMultiMediaStream lpVtbl;
int ref; ULONG ref;
} IAMMultiMediaStreamImpl; } IAMMultiMediaStreamImpl;
static struct IAMMultiMediaStreamVtbl AM_Vtbl; static struct IAMMultiMediaStreamVtbl AM_Vtbl;
@ -83,22 +83,21 @@ static ULONG WINAPI IAMMultiMediaStreamImpl_AddRef(IAMMultiMediaStream* iface)
{ {
IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface; IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
FIXME("(%p/%p)\n", iface, This); TRACE("(%p/%p)\n", iface, This);
return InterlockedIncrement(&This->ref);
This->ref++;
return S_OK;
} }
static ULONG WINAPI IAMMultiMediaStreamImpl_Release(IAMMultiMediaStream* iface) static ULONG WINAPI IAMMultiMediaStreamImpl_Release(IAMMultiMediaStream* iface)
{ {
IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface; IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
ULONG ref = InterlockedDecrement(&This->ref);
FIXME("(%p/%p)\n", iface, This); TRACE("(%p/%p)\n", iface, This);
if (!--This->ref) if (!ref)
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
return S_OK; return ref;
} }
/*** IMultiMediaStream methods ***/ /*** IMultiMediaStream methods ***/

View File

@ -56,14 +56,17 @@ static HRESULT WINAPI COMCAT_IClassFactory_QueryInterface(
static ULONG WINAPI COMCAT_IClassFactory_AddRef(LPCLASSFACTORY iface) static ULONG WINAPI COMCAT_IClassFactory_AddRef(LPCLASSFACTORY iface)
{ {
ClassFactoryImpl *This = (ClassFactoryImpl *)iface; ClassFactoryImpl *This = (ClassFactoryImpl *)iface;
ULONG ref;
TRACE("\n"); TRACE("\n");
if (This == NULL) return E_POINTER; if (This == NULL) return E_POINTER;
if (InterlockedIncrement(&This->ref) == 1) { ref = InterlockedIncrement(&This->ref);
if (ref == 1) {
InterlockedIncrement(&dll_ref); InterlockedIncrement(&dll_ref);
} }
return This->ref; return ref;
} }
/********************************************************************** /**********************************************************************
@ -72,14 +75,17 @@ static ULONG WINAPI COMCAT_IClassFactory_AddRef(LPCLASSFACTORY iface)
static ULONG WINAPI COMCAT_IClassFactory_Release(LPCLASSFACTORY iface) static ULONG WINAPI COMCAT_IClassFactory_Release(LPCLASSFACTORY iface)
{ {
ClassFactoryImpl *This = (ClassFactoryImpl *)iface; ClassFactoryImpl *This = (ClassFactoryImpl *)iface;
ULONG ref;
TRACE("\n"); TRACE("\n");
if (This == NULL) return E_POINTER; if (This == NULL) return E_POINTER;
if (InterlockedDecrement(&This->ref) == 0) { ref = InterlockedDecrement(&This->ref);
if (ref == 0) {
InterlockedDecrement(&dll_ref); InterlockedDecrement(&dll_ref);
} }
return This->ref; return ref;
} }
/********************************************************************** /**********************************************************************

View File

@ -307,11 +307,12 @@ typedef struct
static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_AddRef(LPENUMCATEGORYINFO iface) static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_AddRef(LPENUMCATEGORYINFO iface)
{ {
IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface; IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
TRACE("\n"); TRACE("\n");
if (This == NULL) return E_POINTER; if (This == NULL) return E_POINTER;
return ++(This->ref); return InterlockedIncrement(&This->ref);
} }
static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_QueryInterface( static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_QueryInterface(
@ -338,16 +339,19 @@ static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_QueryInterface(
static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_Release(LPENUMCATEGORYINFO iface) static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_Release(LPENUMCATEGORYINFO iface)
{ {
IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface; IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
ULONG ref;
TRACE("\n"); TRACE("\n");
if (This == NULL) return E_POINTER; if (This == NULL) return E_POINTER;
if (--(This->ref) == 0) { ref = InterlockedDecrement(&This->ref);
if (ref == 0) {
if (This->key) RegCloseKey(This->key); if (This->key) RegCloseKey(This->key);
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
return 0; return 0;
} }
return This->ref; return ref;
} }
static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Next( static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Next(
@ -613,7 +617,7 @@ static ULONG WINAPI COMCAT_CLSID_IEnumGUID_AddRef(LPENUMGUID iface)
if (This == NULL) return E_POINTER; if (This == NULL) return E_POINTER;
return ++(This->ref); return InterlockedIncrement(&This->ref);
} }
static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_QueryInterface( static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_QueryInterface(
@ -640,17 +644,20 @@ static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_QueryInterface(
static ULONG WINAPI COMCAT_CLSID_IEnumGUID_Release(LPENUMGUID iface) static ULONG WINAPI COMCAT_CLSID_IEnumGUID_Release(LPENUMGUID iface)
{ {
CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface; CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
ULONG ref;
TRACE("\n"); TRACE("\n");
if (This == NULL) return E_POINTER; if (This == NULL) return E_POINTER;
if (--(This->ref) == 0) { ref = InterlockedDecrement(&This->ref);
if (ref == 0) {
if (This->key) RegCloseKey(This->key); if (This->key) RegCloseKey(This->key);
HeapFree(GetProcessHeap(), 0, (LPVOID)This->categories); HeapFree(GetProcessHeap(), 0, (LPVOID)This->categories);
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
return 0; return 0;
} }
return This->ref; return ref;
} }
static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Next( static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Next(
@ -805,7 +812,7 @@ static ULONG WINAPI COMCAT_CATID_IEnumGUID_AddRef(LPENUMGUID iface)
if (This == NULL) return E_POINTER; if (This == NULL) return E_POINTER;
return ++(This->ref); return InterlockedIncrement(&This->ref);
} }
static HRESULT WINAPI COMCAT_CATID_IEnumGUID_QueryInterface( static HRESULT WINAPI COMCAT_CATID_IEnumGUID_QueryInterface(
@ -832,16 +839,19 @@ static HRESULT WINAPI COMCAT_CATID_IEnumGUID_QueryInterface(
static ULONG WINAPI COMCAT_CATID_IEnumGUID_Release(LPENUMGUID iface) static ULONG WINAPI COMCAT_CATID_IEnumGUID_Release(LPENUMGUID iface)
{ {
CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface; CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
ULONG ref;
TRACE("\n"); TRACE("\n");
if (This == NULL) return E_POINTER; if (This == NULL) return E_POINTER;
if (--(This->ref) == 0) { ref = InterlockedDecrement(&This->ref);
if (ref == 0) {
if (This->key) RegCloseKey(This->key); if (This->key) RegCloseKey(This->key);
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
return 0; return 0;
} }
return This->ref; return ref;
} }
static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Next( static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Next(

View File

@ -66,14 +66,17 @@ static HRESULT WINAPI COMCAT_IUnknown_QueryInterface(
static ULONG WINAPI COMCAT_IUnknown_AddRef(LPUNKNOWN iface) static ULONG WINAPI COMCAT_IUnknown_AddRef(LPUNKNOWN iface)
{ {
ICOM_THIS_MULTI(ComCatMgrImpl, unkVtbl, iface); ICOM_THIS_MULTI(ComCatMgrImpl, unkVtbl, iface);
ULONG ref;
TRACE("\n"); TRACE("\n");
if (This == NULL) return E_POINTER; if (This == NULL) return E_POINTER;
if (InterlockedIncrement(&This->ref) == 1) { ref = InterlockedIncrement(&This->ref);
if (ref == 1) {
InterlockedIncrement(&dll_ref); InterlockedIncrement(&dll_ref);
} }
return This->ref; return ref;
} }
/********************************************************************** /**********************************************************************
@ -82,14 +85,17 @@ static ULONG WINAPI COMCAT_IUnknown_AddRef(LPUNKNOWN iface)
static ULONG WINAPI COMCAT_IUnknown_Release(LPUNKNOWN iface) static ULONG WINAPI COMCAT_IUnknown_Release(LPUNKNOWN iface)
{ {
ICOM_THIS_MULTI(ComCatMgrImpl, unkVtbl, iface); ICOM_THIS_MULTI(ComCatMgrImpl, unkVtbl, iface);
ULONG ref;
TRACE("\n"); TRACE("\n");
if (This == NULL) return E_POINTER; if (This == NULL) return E_POINTER;
if (InterlockedDecrement(&This->ref) == 0) { ref = InterlockedDecrement(&This->ref);
if (ref == 0) {
InterlockedDecrement(&dll_ref); InterlockedDecrement(&dll_ref);
} }
return This->ref; return ref;
} }
/********************************************************************** /**********************************************************************

View File

@ -216,10 +216,11 @@ HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface,
ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface) ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface)
{ {
IShellBrowserImpl *This = (IShellBrowserImpl *)iface; IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
ULONG ref = InterlockedIncrement(&This->ref);
TRACE("(%p,%lu)\n", This, This->ref); TRACE("(%p,%lu)\n", This, ref - 1);
return ++(This->ref); return ref;
} }
/************************************************************************** /**************************************************************************
@ -228,16 +229,17 @@ ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface)
ULONG WINAPI IShellBrowserImpl_Release(IShellBrowser * iface) ULONG WINAPI IShellBrowserImpl_Release(IShellBrowser * iface)
{ {
IShellBrowserImpl *This = (IShellBrowserImpl *)iface; IShellBrowserImpl *This = (IShellBrowserImpl *)iface;
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p,%lu)\n", This, This->ref); TRACE("(%p,%lu)\n", This, ref + 1);
if (!--(This->ref)) if (!ref)
{ {
COMDLG32_SHFree(This); COMDLG32_SHFree(This);
TRACE("-- destroyed\n"); TRACE("-- destroyed\n");
return 0; return 0;
} }
return This->ref; return ref;
} }
/* /*

View File

@ -84,16 +84,17 @@ static ULONG WINAPI DEVENUM_IPropertyBag_AddRef(LPPROPERTYBAG iface)
static ULONG WINAPI DEVENUM_IPropertyBag_Release(LPPROPERTYBAG iface) static ULONG WINAPI DEVENUM_IPropertyBag_Release(LPPROPERTYBAG iface)
{ {
RegPropBagImpl *This = (RegPropBagImpl *)iface; RegPropBagImpl *This = (RegPropBagImpl *)iface;
ULONG ref;
TRACE("\n"); TRACE("\n");
if (InterlockedDecrement(&This->ref) == 0) { ref = InterlockedDecrement(&This->ref);
if (ref == 0) {
RegCloseKey(This->hkey); RegCloseKey(This->hkey);
CoTaskMemFree(This); CoTaskMemFree(This);
DEVENUM_UnlockModule(); DEVENUM_UnlockModule();
return 0;
} }
return This->ref; return ref;
} }
static HRESULT WINAPI DEVENUM_IPropertyBag_Read( static HRESULT WINAPI DEVENUM_IPropertyBag_Read(