diff options
author | jian liang <jianliang79@gmail.com> | 2012-02-29 14:46:03 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-29 17:00:03 (GMT) |
commit | ad70be4e5b5c55bd838c389bda7d83c2726a69ea (patch) | |
tree | fd0ec1eed4288a827bfa9baa5a04e5dab422d3ff | |
parent | b37ff9aa49569782aa000f04bd0ad24aa0dfad47 (diff) | |
download | Qt-ad70be4e5b5c55bd838c389bda7d83c2726a69ea.zip Qt-ad70be4e5b5c55bd838c389bda7d83c2726a69ea.tar.gz Qt-ad70be4e5b5c55bd838c389bda7d83c2726a69ea.tar.bz2 |
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 <joerg.bornemann@nokia.com>
-rw-r--r-- | src/activeqt/container/qaxbase.cpp | 27 | ||||
-rw-r--r-- | 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<DISPID, QByteArray> 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; } /* |