summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjian liang <jianliang79@gmail.com>2012-03-01 23:55:42 +0800
committerQt by Nokia <qt-info@nokia.com>2012-03-01 18:02:44 +0100
commit8e8f5991f755f473ba109e0cc4cc0ee927620ed9 (patch)
tree391c57f98416467f855c07079c23699b2ef6202f /src
parent230fe9ff1ab037910071a6b7e2656df158a787f1 (diff)
downloadqtactiveqt-8e8f5991f755f473ba109e0cc4cc0ee927620ed9.tar.gz
minor speed improvement to reference counting in qaxserverbase.cpp
Using critical section to implement reference counting in qaxserverbase.cpp is an overkill. This patch use InterlockedIncrement() and InterlockedDecrement() to implement reference counting. Change-Id: I658c87e6a459762e3ea8e5019f4514d5348164fb Reviewed-by: Joerg Bornemann <joerg.bornemann@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/activeqt/control/qaxserverbase.cpp97
1 files changed, 30 insertions, 67 deletions
diff --git a/src/activeqt/control/qaxserverbase.cpp b/src/activeqt/control/qaxserverbase.cpp
index d66e842..9e028e7 100644
--- a/src/activeqt/control/qaxserverbase.cpp
+++ b/src/activeqt/control/qaxserverbase.cpp
@@ -173,26 +173,18 @@ public:
if (m_outerUnknown)
return m_outerUnknown->AddRef();
- EnterCriticalSection(&refCountSection);
- unsigned long r = ++ref;
- LeaveCriticalSection(&refCountSection);
-
- return r;
+ return InterlockedIncrement(&ref);
}
unsigned long WINAPI Release()
{
if (m_outerUnknown)
return m_outerUnknown->Release();
- EnterCriticalSection(&refCountSection);
- unsigned long r = --ref;
- LeaveCriticalSection(&refCountSection);
+ LONG refCount = InterlockedDecrement(&ref);
+ if (!refCount)
+ delete this;
- if (!r) {
- delete this;
- return 0;
- }
- return r;
+ return refCount;
}
HRESULT WINAPI QueryInterface(REFIID iid, void **iface);
HRESULT InternalQueryInterface(REFIID iid, void **iface);
@@ -393,7 +385,7 @@ private:
CRITICAL_SECTION refCountSection;
CRITICAL_SECTION createWindowSection;
- unsigned long ref;
+ LONG ref;
unsigned long ole_ref;
QString class_name;
@@ -436,23 +428,15 @@ public:
// IUnknown
unsigned long WINAPI AddRef()
{
- EnterCriticalSection(&refCountSection);
- unsigned long r = ++ref;
- LeaveCriticalSection(&refCountSection);
-
- return r;
+ return InterlockedIncrement(&ref);
}
unsigned long WINAPI Release()
{
- EnterCriticalSection(&refCountSection);
- unsigned long r = --ref;
- LeaveCriticalSection(&refCountSection);
+ LONG refCount = InterlockedDecrement(&ref);
+ if (!refCount)
+ delete this;
- if (!r) {
- delete this;
- return 0;
- }
- return r;
+ return refCount;
}
HRESULT WINAPI QueryInterface(REFIID iid, void **iface)
{
@@ -470,7 +454,7 @@ public:
private:
QAxServerBase *object;
IUnknown *m_outerUnknown;
- unsigned long ref;
+ LONG ref;
CRITICAL_SECTION refCountSection;
CRITICAL_SECTION createWindowSection;
@@ -521,22 +505,15 @@ public:
unsigned long __stdcall AddRef()
{
- EnterCriticalSection(&refCountSection);
- unsigned long r = ++ref;
- LeaveCriticalSection(&refCountSection);
- return ++r;
+ return InterlockedIncrement(&ref);
}
unsigned long __stdcall Release()
{
- EnterCriticalSection(&refCountSection);
- unsigned long r = --ref;
- LeaveCriticalSection(&refCountSection);
+ LONG refCount = InterlockedDecrement(&ref);
+ if (!refCount)
+ delete this;
- if (!r) {
- delete this;
- return 0;
- }
- return r;
+ return refCount;
}
STDMETHOD(QueryInterface)(REFIID iid, void **iface)
{
@@ -595,7 +572,7 @@ public:
private:
CRITICAL_SECTION refCountSection;
- unsigned long ref;
+ LONG ref;
};
/*
@@ -635,22 +612,15 @@ public:
unsigned long __stdcall AddRef()
{
- EnterCriticalSection(&refCountSection);
- unsigned long r = ++ref;
- LeaveCriticalSection(&refCountSection);
- return r;
+ return InterlockedIncrement(&ref);
}
unsigned long __stdcall Release()
{
- EnterCriticalSection(&refCountSection);
- unsigned long r = --ref;
- LeaveCriticalSection(&refCountSection);
+ LONG refCount = InterlockedDecrement(&ref);
+ if (!refCount)
+ delete this;
- if (!r) {
- delete this;
- return 0;
- }
- return r;
+ return refCount;
}
STDMETHOD(QueryInterface)(REFIID iid, void **iface)
{
@@ -761,7 +731,7 @@ private:
Iterator it;
CRITICAL_SECTION refCountSection;
- unsigned long ref;
+ LONG ref;
};
// callback for DLL server to hook into non-Qt eventloop
@@ -841,22 +811,15 @@ public:
// IUnknown
unsigned long WINAPI AddRef()
{
- EnterCriticalSection(&refCountSection);
- unsigned long r = ++ref;
- LeaveCriticalSection(&refCountSection);
- return ++r;
+ return InterlockedIncrement(&ref);
}
unsigned long WINAPI Release()
{
- EnterCriticalSection(&refCountSection);
- unsigned long r = --ref;
- LeaveCriticalSection(&refCountSection);
+ LONG refCount = InterlockedDecrement(&ref);
+ if (!refCount)
+ delete this;
- if (!r) {
- delete this;
- return 0;
- }
- return r;
+ return refCount;
}
HRESULT WINAPI QueryInterface(REFIID iid, LPVOID *iface)
{
@@ -984,7 +947,7 @@ public:
protected:
CRITICAL_SECTION refCountSection;
- unsigned long ref;
+ LONG ref;
bool licensed;
QString classKey;
};