From 78faf96e5fd4bf6c1f37aa7f89229fa9bf3dd70d Mon Sep 17 00:00:00 2001 From: Jian Liang Date: Wed, 29 Feb 2012 09:23:47 +0800 Subject: Make reference counting for QAxClientSite multi-processor safe It is not safe to use ++long/--long to implement reference counting for COM object in multi-processor environment. We use InterlockedIncrement() and InterlockedDecrement() to implement reference counting. Change-Id: Ibfc5f3456cbaefb9267feb378483c5c60c305f00 Reviewed-by: Bradley T. Hughes Reviewed-by: Joerg Bornemann --- src/activeqt/container/qaxwidget.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/activeqt/container/qaxwidget.cpp b/src/activeqt/container/qaxwidget.cpp index 92a1e11729..a11ac7a61b 100644 --- a/src/activeqt/container/qaxwidget.cpp +++ b/src/activeqt/container/qaxwidget.cpp @@ -408,7 +408,7 @@ private: CONTROLINFO control_info; QSize sizehint; - unsigned long ref; + LONG ref; QAxWidget *widget; QAxHostWidget *host; #if !defined(Q_WS_WINCE) @@ -774,16 +774,16 @@ void QAxClientSite::deactivate() //**** IUnknown unsigned long WINAPI QAxClientSite::AddRef() { - return ++ref; + return InterlockedIncrement(&ref); } unsigned long WINAPI QAxClientSite::Release() { - if (!--ref) { + LONG refCount = InterlockedDecrement(&ref); + if (!refCount) delete this; - return 0; - } - return ref; + + return refCount; } HRESULT WINAPI QAxClientSite::QueryInterface(REFIID iid, void **iface) -- cgit v1.2.3