KDE/kdelibs/solid/solid/backends/wmi
Ralf Habacker
Ralf.Habacker at freenet.de
Wed Jun 24 08:12:25 CEST 2009
SVN commit 986074 by habacker:
bug fix -> "When WmiQuery is created as static global object a dead lock problem occurs"
CCMAIL:kde-windows at kde.org
M +21 -5 wmidevice.cpp
--- trunk/KDE/kdelibs/solid/solid/backends/wmi/wmidevice.cpp #986073:986074
@@ -69,10 +69,24 @@
, m_wmiProperty()
, m_wmiValue()
{
+ /*
+ To avoid multiple connects to wmi in a single application
+ one WmiQuery object is used.
+ When WmiQuery is created as static global object
+ a dead lock problem occurs (see wmiquery.cpp for details).
+ Because solid is only qt based and Q_GLOBAL_STATIC is
+ marked as internal we make our own reference counting.
+ */
+ m_instanceCount++;
+ if (!m_query && m_instanceCount == 1)
+ m_query = new WmiQuery;
}
~WmiDevicePrivate()
{
+ m_instanceCount--;
+ if (m_instanceCount == 0)
+ delete m_query;
}
void discoverType()
@@ -90,7 +104,7 @@
WmiQuery::ItemList sendQuery()
{
QString query("SELECT * FROM " + m_wmiTable + " WHERE " + m_wmiProperty + "='" + m_wmiValue + "'");
- WmiQuery::ItemList list = m_query.sendQuery(query);
+ WmiQuery::ItemList list = m_query->sendQuery(query);
return list;
}
@@ -119,7 +133,7 @@
return false;
QString query("SELECT * FROM " + wmiTable + " WHERE " + wmiProperty + "='" + wmiValue + "'");
- WmiQuery::ItemList list = m_query.sendQuery(query);
+ WmiQuery::ItemList list = m_query->sendQuery(query);
return list.size() > 0;
}
@@ -256,7 +270,7 @@
{
QStringList result;
- WmiQuery::ItemList list = m_query.sendQuery( "select * from " + getWMITable(type) );
+ WmiQuery::ItemList list = m_query->sendQuery( "select * from " + getWMITable(type) );
foreach(WmiQuery::Item *item, list) {
QString propertyName = getPropertyNameForUDI(type);
QString property = item->getProperty(propertyName);
@@ -267,7 +281,8 @@
}
WmiDevice *parent;
- static WmiQuery m_query;
+ static WmiQuery *m_query;
+ static int m_instanceCount;
QString m_udi;
QString m_wmiTable;
QString m_wmiProperty;
@@ -275,7 +290,8 @@
QStringList interfaceList;
};
-WmiQuery WmiDevicePrivate::m_query;
+WmiQuery *WmiDevicePrivate::m_query = 0;
+int WmiDevicePrivate::m_instanceCount = 0;
Q_DECLARE_METATYPE(ChangeDescription)
Q_DECLARE_METATYPE(QList<ChangeDescription>)
More information about the Kde-windows
mailing list