Use InterlockedDecrement and InterlockedIncrement instead of ++/--.

This commit is contained in:
James Hawkins 2004-09-16 19:08:23 +00:00 committed by Alexandre Julliard
parent b970aeb4b7
commit 2d044dd64b
2 changed files with 11 additions and 17 deletions

View File

@ -284,17 +284,19 @@ static ULONG WINAPI IAVIFile_fnAddRef(IAVIFile *iface)
IAVIFileImpl *This = (IAVIFileImpl *)iface; IAVIFileImpl *This = (IAVIFileImpl *)iface;
TRACE("(%p) -> %ld\n", iface, This->ref + 1); TRACE("(%p) -> %ld\n", iface, This->ref + 1);
return ++(This->ref); return InterlockedIncrement(&This->ref);
} }
static ULONG WINAPI IAVIFile_fnRelease(IAVIFile *iface) static ULONG WINAPI IAVIFile_fnRelease(IAVIFile *iface)
{ {
IAVIFileImpl *This = (IAVIFileImpl *)iface; IAVIFileImpl *This = (IAVIFileImpl *)iface;
UINT i; UINT i;
ULONG ret;
TRACE("(%p) -> %ld\n", iface, This->ref - 1); TRACE("(%p) -> %ld\n", iface, This->ref - 1);
if (!--(This->ref)) { ret = InterlockedDecrement(&This->ref);
if (!ret) {
if (This->fDirty) { if (This->fDirty) {
/* need to write headers to file */ /* need to write headers to file */
AVIFILE_SaveFile(This); AVIFILE_SaveFile(This);
@ -334,9 +336,8 @@ static ULONG WINAPI IAVIFile_fnRelease(IAVIFile *iface)
} }
LocalFree((HLOCAL)This); LocalFree((HLOCAL)This);
return 0;
} }
return This->ref; return ret;
} }
static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile *iface, LPAVIFILEINFOW afi, static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile *iface, LPAVIFILEINFOW afi,
@ -743,27 +744,20 @@ static ULONG WINAPI IAVIStream_fnAddRef(IAVIStream *iface)
if (This->paf != NULL) if (This->paf != NULL)
IAVIFile_AddRef((PAVIFILE)This->paf); IAVIFile_AddRef((PAVIFILE)This->paf);
return ++(This->ref); return InterlockedIncrement(&This->ref);
} }
static ULONG WINAPI IAVIStream_fnRelease(IAVIStream* iface) static ULONG WINAPI IAVIStream_fnRelease(IAVIStream* iface)
{ {
IAVIStreamImpl *This = (IAVIStreamImpl *)iface; IAVIStreamImpl *This = (IAVIStreamImpl *)iface;
ULONG ret = InterlockedDecrement(&This->ref);
TRACE("(%p) -> %ld\n", iface, This->ref - 1); TRACE("(%p) -> %ld\n", iface, ret);
/* we belong to the AVIFile, which must free us! */
if (This->ref == 0) {
ERR(": already released!\n");
return 0;
}
This->ref--;
if (This->paf != NULL) if (This->paf != NULL)
IAVIFile_Release((PAVIFILE)This->paf); IAVIFile_Release((PAVIFILE)This->paf);
return This->ref; return ret;
} }
static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream *iface, LPARAM lParam1, static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream *iface, LPARAM lParam1,

View File

@ -527,13 +527,13 @@ static DummyDispatch dispatch;
static ULONG WINAPI DummyDispatch_AddRef(LPDISPATCH iface) static ULONG WINAPI DummyDispatch_AddRef(LPDISPATCH iface)
{ {
trace("AddRef(%p)\n", iface); trace("AddRef(%p)\n", iface);
return ++((DummyDispatch*)iface)->ref; return InterlockedIncrement(&((DummyDispatch*)iface)->ref);
} }
static ULONG WINAPI DummyDispatch_Release(LPDISPATCH iface) static ULONG WINAPI DummyDispatch_Release(LPDISPATCH iface)
{ {
trace("Release(%p)\n", iface); trace("Release(%p)\n", iface);
return ((DummyDispatch*)iface)->ref--; return InterlockedDecrement(&((DummyDispatch*)iface)->ref);
} }
static HRESULT WINAPI DummyDispatch_QueryInterface(LPDISPATCH iface, static HRESULT WINAPI DummyDispatch_QueryInterface(LPDISPATCH iface,