From 2d044dd64bdff2efea142242f5a8d14db5235490 Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Thu, 16 Sep 2004 19:08:23 +0000 Subject: [PATCH] Use InterlockedDecrement and InterlockedIncrement instead of ++/--. --- dlls/avifil32/avifile.c | 24 +++++++++--------------- dlls/oleaut32/tests/vartype.c | 4 ++-- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/dlls/avifil32/avifile.c b/dlls/avifil32/avifile.c index 505d5da5930..ec1aae3a86a 100644 --- a/dlls/avifil32/avifile.c +++ b/dlls/avifil32/avifile.c @@ -284,17 +284,19 @@ static ULONG WINAPI IAVIFile_fnAddRef(IAVIFile *iface) IAVIFileImpl *This = (IAVIFileImpl *)iface; TRACE("(%p) -> %ld\n", iface, This->ref + 1); - return ++(This->ref); + return InterlockedIncrement(&This->ref); } static ULONG WINAPI IAVIFile_fnRelease(IAVIFile *iface) { IAVIFileImpl *This = (IAVIFileImpl *)iface; UINT i; + ULONG ret; TRACE("(%p) -> %ld\n", iface, This->ref - 1); - if (!--(This->ref)) { + ret = InterlockedDecrement(&This->ref); + if (!ret) { if (This->fDirty) { /* need to write headers to file */ AVIFILE_SaveFile(This); @@ -334,9 +336,8 @@ static ULONG WINAPI IAVIFile_fnRelease(IAVIFile *iface) } LocalFree((HLOCAL)This); - return 0; } - return This->ref; + return ret; } static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile *iface, LPAVIFILEINFOW afi, @@ -743,27 +744,20 @@ static ULONG WINAPI IAVIStream_fnAddRef(IAVIStream *iface) if (This->paf != NULL) IAVIFile_AddRef((PAVIFILE)This->paf); - return ++(This->ref); + return InterlockedIncrement(&This->ref); } static ULONG WINAPI IAVIStream_fnRelease(IAVIStream* iface) { IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + ULONG ret = InterlockedDecrement(&This->ref); - TRACE("(%p) -> %ld\n", iface, This->ref - 1); - - /* we belong to the AVIFile, which must free us! */ - if (This->ref == 0) { - ERR(": already released!\n"); - return 0; - } - - This->ref--; + TRACE("(%p) -> %ld\n", iface, ret); if (This->paf != NULL) IAVIFile_Release((PAVIFILE)This->paf); - return This->ref; + return ret; } static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream *iface, LPARAM lParam1, diff --git a/dlls/oleaut32/tests/vartype.c b/dlls/oleaut32/tests/vartype.c index d5496371eeb..3f48c90de0a 100644 --- a/dlls/oleaut32/tests/vartype.c +++ b/dlls/oleaut32/tests/vartype.c @@ -527,13 +527,13 @@ static DummyDispatch dispatch; static ULONG WINAPI DummyDispatch_AddRef(LPDISPATCH iface) { trace("AddRef(%p)\n", iface); - return ++((DummyDispatch*)iface)->ref; + return InterlockedIncrement(&((DummyDispatch*)iface)->ref); } static ULONG WINAPI DummyDispatch_Release(LPDISPATCH iface) { trace("Release(%p)\n", iface); - return ((DummyDispatch*)iface)->ref--; + return InterlockedDecrement(&((DummyDispatch*)iface)->ref); } static HRESULT WINAPI DummyDispatch_QueryInterface(LPDISPATCH iface,