Commit 545cdfa2 authored by Paul Vriens's avatar Paul Vriens Committed by Alexandre Julliard

- use Interlocked* functions in AddRef and Release.

- store the result of the Interlocked functions and use only this.
parent b3f064cc
......@@ -36,7 +36,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(amstream);
typedef struct {
IAMMultiMediaStream lpVtbl;
int ref;
ULONG ref;
} IAMMultiMediaStreamImpl;
static struct IAMMultiMediaStreamVtbl AM_Vtbl;
......@@ -83,22 +83,21 @@ static ULONG WINAPI IAMMultiMediaStreamImpl_AddRef(IAMMultiMediaStream* iface)
{
IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
FIXME("(%p/%p)\n", iface, This);
This->ref++;
return S_OK;
TRACE("(%p/%p)\n", iface, This);
return InterlockedIncrement(&This->ref);
}
static ULONG WINAPI IAMMultiMediaStreamImpl_Release(IAMMultiMediaStream* 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);
return S_OK;
return ref;
}
/*** IMultiMediaStream methods ***/
......
......@@ -56,14 +56,17 @@ static HRESULT WINAPI COMCAT_IClassFactory_QueryInterface(
static ULONG WINAPI COMCAT_IClassFactory_AddRef(LPCLASSFACTORY iface)
{
ClassFactoryImpl *This = (ClassFactoryImpl *)iface;
ULONG ref;
TRACE("\n");
if (This == NULL) return E_POINTER;
if (InterlockedIncrement(&This->ref) == 1) {
ref = InterlockedIncrement(&This->ref);
if (ref == 1) {
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)
{
ClassFactoryImpl *This = (ClassFactoryImpl *)iface;
ULONG ref;
TRACE("\n");
if (This == NULL) return E_POINTER;
if (InterlockedDecrement(&This->ref) == 0) {
ref = InterlockedDecrement(&This->ref);
if (ref == 0) {
InterlockedDecrement(&dll_ref);
}
return This->ref;
return ref;
}
/**********************************************************************
......
......@@ -307,11 +307,12 @@ typedef struct
static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_AddRef(LPENUMCATEGORYINFO iface)
{
IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
TRACE("\n");
if (This == NULL) return E_POINTER;
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_QueryInterface(
......@@ -338,16 +339,19 @@ static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_QueryInterface(
static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_Release(LPENUMCATEGORYINFO iface)
{
IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
ULONG ref;
TRACE("\n");
if (This == NULL) return E_POINTER;
if (--(This->ref) == 0) {
ref = InterlockedDecrement(&This->ref);
if (ref == 0) {
if (This->key) RegCloseKey(This->key);
HeapFree(GetProcessHeap(), 0, This);
return 0;
}
return This->ref;
return ref;
}
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;
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
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)
{
CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
ULONG ref;
TRACE("\n");
if (This == NULL) return E_POINTER;
if (--(This->ref) == 0) {
ref = InterlockedDecrement(&This->ref);
if (ref == 0) {
if (This->key) RegCloseKey(This->key);
HeapFree(GetProcessHeap(), 0, (LPVOID)This->categories);
HeapFree(GetProcessHeap(), 0, This);
return 0;
}
return This->ref;
return ref;
}
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;
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
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)
{
CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
ULONG ref;
TRACE("\n");
if (This == NULL) return E_POINTER;
if (--(This->ref) == 0) {
ref = InterlockedDecrement(&This->ref);
if (ref == 0) {
if (This->key) RegCloseKey(This->key);
HeapFree(GetProcessHeap(), 0, This);
return 0;
}
return This->ref;
return ref;
}
static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Next(
......
......@@ -66,14 +66,17 @@ static HRESULT WINAPI COMCAT_IUnknown_QueryInterface(
static ULONG WINAPI COMCAT_IUnknown_AddRef(LPUNKNOWN iface)
{
ICOM_THIS_MULTI(ComCatMgrImpl, unkVtbl, iface);
ULONG ref;
TRACE("\n");
if (This == NULL) return E_POINTER;
if (InterlockedIncrement(&This->ref) == 1) {
ref = InterlockedIncrement(&This->ref);
if (ref == 1) {
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)
{
ICOM_THIS_MULTI(ComCatMgrImpl, unkVtbl, iface);
ULONG ref;
TRACE("\n");
if (This == NULL) return E_POINTER;
if (InterlockedDecrement(&This->ref) == 0) {
ref = InterlockedDecrement(&This->ref);
if (ref == 0) {
InterlockedDecrement(&dll_ref);
}
return This->ref;
return ref;
}
/**********************************************************************
......
......@@ -216,10 +216,11 @@ HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface,
ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * 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)
{
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);
TRACE("-- destroyed\n");
return 0;
}
return This->ref;
return ref;
}
/*
......
......@@ -84,16 +84,17 @@ static ULONG WINAPI DEVENUM_IPropertyBag_AddRef(LPPROPERTYBAG iface)
static ULONG WINAPI DEVENUM_IPropertyBag_Release(LPPROPERTYBAG iface)
{
RegPropBagImpl *This = (RegPropBagImpl *)iface;
ULONG ref;
TRACE("\n");
if (InterlockedDecrement(&This->ref) == 0) {
ref = InterlockedDecrement(&This->ref);
if (ref == 0) {
RegCloseKey(This->hkey);
CoTaskMemFree(This);
DEVENUM_UnlockModule();
return 0;
}
return This->ref;
return ref;
}
static HRESULT WINAPI DEVENUM_IPropertyBag_Read(
......
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