From ad70be4e5b5c55bd838c389bda7d83c2726a69ea Mon Sep 17 00:00:00 2001 From: jian liang Date: Wed, 29 Feb 2012 22:46:03 +0800 Subject: Make reference counting in activeQt container multi-processor safe Use InterlockedIncrement() and InterlockedDecrement() to implement reference couting in activeQt container to make it multi-processor safe. Change-Id: Ibe7daab69c27117bb3e35c10ba273bccd29afc69 Reviewed-by: Joerg Bornemann --- src/activeqt/container/qaxbase.cpp | 27 +++++++++++++++------------ src/activeqt/container/qaxscript.cpp | 12 ++++++------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/activeqt/container/qaxbase.cpp b/src/activeqt/container/qaxbase.cpp index d83c12b..7f9c3c4 100644 --- a/src/activeqt/container/qaxbase.cpp +++ b/src/activeqt/container/qaxbase.cpp @@ -290,15 +290,15 @@ public: // IUnknown unsigned long __stdcall AddRef() { - return ref++; + return InterlockedIncrement(&ref); } unsigned long __stdcall Release() { - if (!--ref) { + LONG refCount = InterlockedDecrement(&ref); + if (!refCount) delete this; - return 0; - } - return ref; + + return refCount; } HRESULT __stdcall QueryInterface(REFIID riid, void **ppvObject) { @@ -538,7 +538,7 @@ public: QMap props; QAxBase *combase; - long ref; + LONG ref; }; /* @@ -4216,14 +4216,17 @@ public: AddRef(); return S_OK; } - unsigned long __stdcall AddRef() { return ++ref; } + unsigned long __stdcall AddRef() + { + return InterlockedIncrement(&ref); + } unsigned long __stdcall Release() { - if (!--ref) { + LONG refCount = InterlockedDecrement(&ref); + if (!refCount) delete this; - return 0; - } - return ref; + + return refCount; } HRESULT __stdcall Read(LPCOLESTR name, VARIANT *var, IErrorLog *) @@ -4250,7 +4253,7 @@ public: QAxBase::PropertyBag map; private: - unsigned long ref; + LONG ref; }; /*! diff --git a/src/activeqt/container/qaxscript.cpp b/src/activeqt/container/qaxscript.cpp index c5504ce..7166998 100644 --- a/src/activeqt/container/qaxscript.cpp +++ b/src/activeqt/container/qaxscript.cpp @@ -113,7 +113,7 @@ protected: private: QAxScript *script; - unsigned long ref; + LONG ref; }; /* @@ -129,7 +129,7 @@ QAxScriptSite::QAxScriptSite(QAxScript *s) */ ULONG WINAPI QAxScriptSite::AddRef() { - return ++ref; + return InterlockedIncrement(&ref); } /* @@ -137,11 +137,11 @@ ULONG WINAPI QAxScriptSite::AddRef() */ ULONG WINAPI QAxScriptSite::Release() { - if (!--ref) { + LONG refCount = InterlockedDecrement(&ref); + if (!refCount) delete this; - return 0; - } - return ref; + + return refCount; } /* -- cgit v0.12