summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjian liang <jianliang79@gmail.com>2012-02-29 22:46:03 +0800
committerQt by Nokia <qt-info@nokia.com>2012-02-29 18:00:03 +0100
commitad70be4e5b5c55bd838c389bda7d83c2726a69ea (patch)
treefd0ec1eed4288a827bfa9baa5a04e5dab422d3ff
parentb37ff9aa49569782aa000f04bd0ad24aa0dfad47 (diff)
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.cpp27
-rw-r--r--src/activeqt/container/qaxscript.cpp12
2 files changed, 21 insertions, 18 deletions
diff --git a/src/activeqt/container/qaxbase.cpp b/src/activeqt/container/qaxbase.cpp
index d83c12b14c..7f9c3c4c2b 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 c5504ced29..7166998e45 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;
}
/*