- 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-14 15:10:52 +00:00 committed by Alexandre Julliard
parent a010e3b3fa
commit c905d691c8
7 changed files with 46 additions and 33 deletions

View File

@ -147,14 +147,15 @@ static HRESULT WINAPI ACMStream_fnQueryInterface(IAVIStream *iface,
static ULONG WINAPI ACMStream_fnAddRef(IAVIStream *iface) static ULONG WINAPI ACMStream_fnAddRef(IAVIStream *iface)
{ {
IAVIStreamImpl *This = (IAVIStreamImpl *)iface; IAVIStreamImpl *This = (IAVIStreamImpl *)iface;
ULONG ref = InterlockedIncrement(&This->ref);
TRACE("(%p) -> %ld\n", iface, This->ref + 1); TRACE("(%p) -> %ld\n", iface, ref);
/* also add reference to the nested stream */ /* also add reference to the nested stream */
if (This->pStream != NULL) if (This->pStream != NULL)
IAVIStream_AddRef(This->pStream); IAVIStream_AddRef(This->pStream);
return ++(This->ref); return ref;
} }
static ULONG WINAPI ACMStream_fnRelease(IAVIStream* iface) static ULONG WINAPI ACMStream_fnRelease(IAVIStream* iface)

View File

@ -282,21 +282,22 @@ static HRESULT WINAPI IAVIFile_fnQueryInterface(IAVIFile *iface, REFIID refiid,
static ULONG WINAPI IAVIFile_fnAddRef(IAVIFile *iface) static ULONG WINAPI IAVIFile_fnAddRef(IAVIFile *iface)
{ {
IAVIFileImpl *This = (IAVIFileImpl *)iface; IAVIFileImpl *This = (IAVIFileImpl *)iface;
ULONG ref = InterlockedIncrement(&This->ref);
TRACE("(%p) -> %ld\n", iface, This->ref + 1); TRACE("(%p) -> %ld\n", iface, ref);
return InterlockedIncrement(&This->ref);
return 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; ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p) -> %ld\n", iface, This->ref - 1); TRACE("(%p) -> %ld\n", iface, ref);
ret = InterlockedDecrement(&This->ref); if (!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);
@ -337,7 +338,7 @@ static ULONG WINAPI IAVIFile_fnRelease(IAVIFile *iface)
LocalFree((HLOCAL)This); LocalFree((HLOCAL)This);
} }
return ret; return ref;
} }
static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile *iface, LPAVIFILEINFOW afi, static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile *iface, LPAVIFILEINFOW afi,
@ -737,27 +738,28 @@ static HRESULT WINAPI IAVIStream_fnQueryInterface(IAVIStream *iface,
static ULONG WINAPI IAVIStream_fnAddRef(IAVIStream *iface) static ULONG WINAPI IAVIStream_fnAddRef(IAVIStream *iface)
{ {
IAVIStreamImpl *This = (IAVIStreamImpl *)iface; IAVIStreamImpl *This = (IAVIStreamImpl *)iface;
ULONG ref = InterlockedIncrement(&This->ref);
TRACE("(%p) -> %ld\n", iface, This->ref + 1); TRACE("(%p) -> %ld\n", iface, ref);
/* also add ref to parent, so that it doesn't kill us */ /* also add ref to parent, so that it doesn't kill us */
if (This->paf != NULL) if (This->paf != NULL)
IAVIFile_AddRef((PAVIFILE)This->paf); IAVIFile_AddRef((PAVIFILE)This->paf);
return InterlockedIncrement(&This->ref); return 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); ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p) -> %ld\n", iface, ret); TRACE("(%p) -> %ld\n", iface, ref);
if (This->paf != NULL) if (This->paf != NULL)
IAVIFile_Release((PAVIFILE)This->paf); IAVIFile_Release((PAVIFILE)This->paf);
return ret; return ref;
} }
static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream *iface, LPARAM lParam1, static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream *iface, LPARAM lParam1,

View File

@ -381,20 +381,23 @@ static HRESULT WINAPI IAVIEditStream_fnQueryInterface(IAVIEditStream*iface,REFII
static ULONG WINAPI IAVIEditStream_fnAddRef(IAVIEditStream*iface) static ULONG WINAPI IAVIEditStream_fnAddRef(IAVIEditStream*iface)
{ {
IAVIEditStreamImpl *This = (IAVIEditStreamImpl *)iface; IAVIEditStreamImpl *This = (IAVIEditStreamImpl *)iface;
ULONG ref = InterlockedIncrement(&This->ref);
TRACE("(%p) -> %ld\n", iface, This->ref + 1); TRACE("(%p) -> %ld\n", iface, ref);
return ++(This->ref);
return ref;
} }
static ULONG WINAPI IAVIEditStream_fnRelease(IAVIEditStream*iface) static ULONG WINAPI IAVIEditStream_fnRelease(IAVIEditStream*iface)
{ {
IAVIEditStreamImpl *This = (IAVIEditStreamImpl *)iface; IAVIEditStreamImpl *This = (IAVIEditStreamImpl *)iface;
DWORD i; DWORD i;
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p) -> %ld\n", iface, This->ref - 1); TRACE("(%p) -> %ld\n", iface, ref);
if (!--(This->ref)) { if (!ref) {
/* releaase memory */ /* release memory */
if (This->pg != NULL) if (This->pg != NULL)
AVIStreamGetFrameClose(This->pg); AVIStreamGetFrameClose(This->pg);
if (This->pStreams != NULL) { if (This->pStreams != NULL) {
@ -408,7 +411,7 @@ static ULONG WINAPI IAVIEditStream_fnRelease(IAVIEditStream*iface)
LocalFree((HLOCAL)This); LocalFree((HLOCAL)This);
return 0; return 0;
} }
return This->ref; return ref;
} }
static HRESULT WINAPI IAVIEditStream_fnCut(IAVIEditStream*iface,LONG*plStart, static HRESULT WINAPI IAVIEditStream_fnCut(IAVIEditStream*iface,LONG*plStart,

View File

@ -155,19 +155,21 @@ static HRESULT WINAPI IGetFrame_fnQueryInterface(IGetFrame *iface,
static ULONG WINAPI IGetFrame_fnAddRef(IGetFrame *iface) static ULONG WINAPI IGetFrame_fnAddRef(IGetFrame *iface)
{ {
IGetFrameImpl *This = (IGetFrameImpl *)iface; IGetFrameImpl *This = (IGetFrameImpl *)iface;
ULONG ref = InterlockedIncrement(&This->ref);
TRACE("(%p)\n", iface); TRACE("(%p)\n", iface);
return ++(This->ref); return ref;
} }
static ULONG WINAPI IGetFrame_fnRelease(IGetFrame *iface) static ULONG WINAPI IGetFrame_fnRelease(IGetFrame *iface)
{ {
IGetFrameImpl *This = (IGetFrameImpl *)iface; IGetFrameImpl *This = (IGetFrameImpl *)iface;
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p)\n", iface); TRACE("(%p)\n", iface);
if (!--(This->ref)) { if (!ref) {
AVIFILE_CloseCompressor(This); AVIFILE_CloseCompressor(This);
if (This->pStream != NULL) { if (This->pStream != NULL) {
IAVIStream_Release(This->pStream); IAVIStream_Release(This->pStream);
@ -178,7 +180,7 @@ static ULONG WINAPI IGetFrame_fnRelease(IGetFrame *iface)
return 0; return 0;
} }
return This->ref; return ref;
} }
static LPVOID WINAPI IGetFrame_fnGetFrame(IGetFrame *iface, LONG lPos) static LPVOID WINAPI IGetFrame_fnGetFrame(IGetFrame *iface, LONG lPos)

View File

@ -163,14 +163,15 @@ static HRESULT WINAPI ICMStream_fnQueryInterface(IAVIStream *iface,
static ULONG WINAPI ICMStream_fnAddRef(IAVIStream *iface) static ULONG WINAPI ICMStream_fnAddRef(IAVIStream *iface)
{ {
IAVIStreamImpl *This = (IAVIStreamImpl *)iface; IAVIStreamImpl *This = (IAVIStreamImpl *)iface;
ULONG ref = InterlockedIncrement(&This->ref);
TRACE("(%p) -> %ld\n", iface, This->ref + 1); TRACE("(%p) -> %ld\n", iface, ref);
/* also add reference to the nested stream */ /* also add reference to the nested stream */
if (This->pStream != NULL) if (This->pStream != NULL)
IAVIStream_AddRef(This->pStream); IAVIStream_AddRef(This->pStream);
return ++(This->ref); return ref;
} }
static ULONG WINAPI ICMStream_fnRelease(IAVIStream* iface) static ULONG WINAPI ICMStream_fnRelease(IAVIStream* iface)

View File

@ -152,18 +152,21 @@ static HRESULT WINAPI ITmpFile_fnQueryInterface(IAVIFile *iface, REFIID refiid,
static ULONG WINAPI ITmpFile_fnAddRef(IAVIFile *iface) static ULONG WINAPI ITmpFile_fnAddRef(IAVIFile *iface)
{ {
ITmpFileImpl *This = (ITmpFileImpl *)iface; ITmpFileImpl *This = (ITmpFileImpl *)iface;
ULONG ref = InterlockedIncrement(&This->ref);
TRACE("(%p) -> %ld\n", iface, This->ref + 1); TRACE("(%p) -> %ld\n", iface, ref);
return ++(This->ref);
return ref;
} }
static ULONG WINAPI ITmpFile_fnRelease(IAVIFile *iface) static ULONG WINAPI ITmpFile_fnRelease(IAVIFile *iface)
{ {
ITmpFileImpl *This = (ITmpFileImpl *)iface; ITmpFileImpl *This = (ITmpFileImpl *)iface;
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p) -> %ld\n", iface, This->ref - 1); TRACE("(%p) -> %ld\n", iface, ref);
if (!--(This->ref)) { if (!ref) {
unsigned int i; unsigned int i;
for (i = 0; i < This->fInfo.dwStreams; i++) { for (i = 0; i < This->fInfo.dwStreams; i++) {
@ -178,7 +181,7 @@ static ULONG WINAPI ITmpFile_fnRelease(IAVIFile *iface)
return 0; return 0;
} }
return This->ref; return ref;
} }
static HRESULT WINAPI ITmpFile_fnInfo(IAVIFile *iface, static HRESULT WINAPI ITmpFile_fnInfo(IAVIFile *iface,

View File

@ -272,16 +272,17 @@ static ULONG WINAPI IAVIFile_fnAddRef(IAVIFile *iface)
TRACE("(%p)\n",iface); TRACE("(%p)\n",iface);
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;
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p)\n",iface); TRACE("(%p)\n",iface);
if (!--(This->ref)) { if (!ref) {
if (This->fDirty) { if (This->fDirty) {
/* need to write headers to file */ /* need to write headers to file */
AVIFILE_SaveFile(This); AVIFILE_SaveFile(This);
@ -309,7 +310,7 @@ static ULONG WINAPI IAVIFile_fnRelease(IAVIFile *iface)
LocalFree((HLOCAL)This); LocalFree((HLOCAL)This);
return 0; return 0;
} }
return This->ref; return ref;
} }
static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile *iface, LPAVIFILEINFOW afi, static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile *iface, LPAVIFILEINFOW afi,