Revert "Merge the QDBusMetaType's custom information to QDBusConnectionManager"

This reverts commit daeb334039e9dcc01485995f53552749131a06b7.

The commit was causing race conditions, and random failures in CI.

Task-number: QTBUG-60792
Change-Id: I6e49b733965632a1a268f0e88809794098465ec0
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Lars Knoll 2017-05-17 13:07:14 +02:00
parent 3f1548ae82
commit 51f095e655
6 changed files with 91 additions and 125 deletions

View File

@ -190,7 +190,6 @@ void QDBusConnectionManager::run()
} }
} }
connectionHash.clear(); connectionHash.clear();
customTypes.clear();
// allow deletion from any thread without warning // allow deletion from any thread without warning
moveToThread(Q_NULLPTR); moveToThread(Q_NULLPTR);

View File

@ -55,14 +55,13 @@
#include <QtDBus/private/qtdbusglobal_p.h> #include <QtDBus/private/qtdbusglobal_p.h>
#include "qdbusconnection_p.h" #include "qdbusconnection_p.h"
#include "qdbusmetatype_p.h"
#include "private/qthread_p.h" #include "private/qthread_p.h"
#ifndef QT_NO_DBUS #ifndef QT_NO_DBUS
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QDBusConnectionManager : public QDaemonThread, public QDBusMetaTypeId class QDBusConnectionManager : public QDaemonThread
{ {
Q_OBJECT Q_OBJECT
struct ConnectionRequestData; struct ConnectionRequestData;

View File

@ -1039,6 +1039,7 @@ QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *p)
qdbusThreadDebug = qdbusDefaultThreadDebug; qdbusThreadDebug = qdbusDefaultThreadDebug;
#endif #endif
QDBusMetaTypeId::init();
connect(this, &QDBusConnectionPrivate::dispatchStatusChanged, connect(this, &QDBusConnectionPrivate::dispatchStatusChanged,
this, &QDBusConnectionPrivate::doDispatch, Qt::QueuedConnection); this, &QDBusConnectionPrivate::doDispatch, Qt::QueuedConnection);
connect(this, &QDBusConnectionPrivate::spyHooksFinished, connect(this, &QDBusConnectionPrivate::spyHooksFinished,

View File

@ -1,7 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2016 The Qt Company Ltd. ** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the QtDBus module of the Qt Toolkit. ** This file is part of the QtDBus module of the Qt Toolkit.
@ -40,15 +39,19 @@
#include "qdbusmetatype.h" #include "qdbusmetatype.h"
#include "qdbusmetatype_p.h" #include "qdbusmetatype_p.h"
#include "qdbus_symbols_p.h"
#include <string.h> #include <string.h>
#include "qdbus_symbols_p.h"
#include <qbytearray.h>
#include <qglobal.h>
#include <qreadwritelock.h>
#include <qvector.h>
#include "qdbusargument_p.h" #include "qdbusargument_p.h"
#include "qdbusutil_p.h" #include "qdbusutil_p.h"
#include "qdbusunixfiledescriptor.h" #include "qdbusunixfiledescriptor.h"
#ifndef QT_BOOTSTRAPPED #ifndef QT_BOOTSTRAPPED
#include "qdbusconnectionmanager_p.h"
#include "qdbusmessage.h" #include "qdbusmessage.h"
#endif #endif
@ -61,72 +64,82 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
static void registerMarshallOperatorsNoLock(QVector<QDBusCustomTypeInfo> &ct, int id, class QDBusCustomTypeInfo
QDBusMetaType::MarshallFunction mf, {
QDBusMetaType::DemarshallFunction df); public:
QDBusCustomTypeInfo() : signature(), marshall(0), demarshall(0)
{ }
// Suggestion:
// change 'signature' to char* and make QDBusCustomTypeInfo a Movable type
QByteArray signature;
QDBusMetaType::MarshallFunction marshall;
QDBusMetaType::DemarshallFunction demarshall;
};
template<typename T> template<typename T>
inline static void registerHelper(QVector<QDBusCustomTypeInfo> &ct) inline static void registerHelper(T * = 0)
{ {
void (*mf)(QDBusArgument &, const T *) = qDBusMarshallHelper<T>; void (*mf)(QDBusArgument &, const T *) = qDBusMarshallHelper<T>;
void (*df)(const QDBusArgument &, T *) = qDBusDemarshallHelper<T>; void (*df)(const QDBusArgument &, T *) = qDBusDemarshallHelper<T>;
registerMarshallOperatorsNoLock(ct, qMetaTypeId<T>(), QDBusMetaType::registerMarshallOperators(qMetaTypeId<T>(),
reinterpret_cast<QDBusMetaType::MarshallFunction>(mf), reinterpret_cast<QDBusMetaType::MarshallFunction>(mf),
reinterpret_cast<QDBusMetaType::DemarshallFunction>(df)); reinterpret_cast<QDBusMetaType::DemarshallFunction>(df));
} }
QDBusMetaTypeId *QDBusMetaTypeId::instance() void QDBusMetaTypeId::init()
{ {
#ifdef QT_BOOTSTRAPPED static QBasicAtomicInt initialized = Q_BASIC_ATOMIC_INITIALIZER(false);
static QDBusMetaTypeId self;
return &self;
#else
return QDBusConnectionManager::instance();
#endif
}
QDBusMetaTypeId::QDBusMetaTypeId() // reentrancy is not a problem since everything else is locked on their own
{ // set the guard variable at the end
// register our types with Qt Core (calling qMetaTypeId<T>() does this implicitly) if (!initialized.load()) {
(void)message(); // register our types with Qt Core (calling qMetaTypeId<T>() does this implicitly)
(void)argument(); (void)message();
(void)variant(); (void)argument();
(void)objectpath(); (void)variant();
(void)signature(); (void)objectpath();
(void)error(); (void)signature();
(void)unixfd(); (void)error();
(void)unixfd();
#ifndef QDBUS_NO_SPECIALTYPES #ifndef QDBUS_NO_SPECIALTYPES
// and register Qt Core's with us // and register Qt Core's with us
registerHelper<QDate>(customTypes); registerHelper<QDate>();
registerHelper<QTime>(customTypes); registerHelper<QTime>();
registerHelper<QDateTime>(customTypes); registerHelper<QDateTime>();
registerHelper<QRect>(customTypes); registerHelper<QRect>();
registerHelper<QRectF>(customTypes); registerHelper<QRectF>();
registerHelper<QSize>(customTypes); registerHelper<QSize>();
registerHelper<QSizeF>(customTypes); registerHelper<QSizeF>();
registerHelper<QPoint>(customTypes); registerHelper<QPoint>();
registerHelper<QPointF>(customTypes); registerHelper<QPointF>();
registerHelper<QLine>(customTypes); registerHelper<QLine>();
registerHelper<QLineF>(customTypes); registerHelper<QLineF>();
registerHelper<QVariantList>(customTypes); registerHelper<QVariantList>();
registerHelper<QVariantMap>(customTypes); registerHelper<QVariantMap>();
registerHelper<QVariantHash>(customTypes); registerHelper<QVariantHash>();
registerHelper<QList<bool> >(customTypes); qDBusRegisterMetaType<QList<bool> >();
registerHelper<QList<short> >(customTypes); qDBusRegisterMetaType<QList<short> >();
registerHelper<QList<ushort> >(customTypes); qDBusRegisterMetaType<QList<ushort> >();
registerHelper<QList<int> >(customTypes); qDBusRegisterMetaType<QList<int> >();
registerHelper<QList<uint> >(customTypes); qDBusRegisterMetaType<QList<uint> >();
registerHelper<QList<qlonglong> >(customTypes); qDBusRegisterMetaType<QList<qlonglong> >();
registerHelper<QList<qulonglong> >(customTypes); qDBusRegisterMetaType<QList<qulonglong> >();
registerHelper<QList<double> >(customTypes); qDBusRegisterMetaType<QList<double> >();
registerHelper<QList<QDBusObjectPath> >(customTypes); qDBusRegisterMetaType<QList<QDBusObjectPath> >();
registerHelper<QList<QDBusSignature> >(customTypes); qDBusRegisterMetaType<QList<QDBusSignature> >();
registerHelper<QList<QDBusUnixFileDescriptor> >(customTypes); qDBusRegisterMetaType<QList<QDBusUnixFileDescriptor> >();
#endif #endif
initialized.store(true);
}
} }
Q_GLOBAL_STATIC(QVector<QDBusCustomTypeInfo>, customTypes)
Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
/*! /*!
\class QDBusMetaType \class QDBusMetaType
\inmodule QtDBus \inmodule QtDBus
@ -204,22 +217,14 @@ void QDBusMetaType::registerMarshallOperators(int id, MarshallFunction mf,
DemarshallFunction df) DemarshallFunction df)
{ {
QByteArray var; QByteArray var;
QDBusMetaTypeId *mgr = QDBusMetaTypeId::instance(); QVector<QDBusCustomTypeInfo> *ct = customTypes();
if (id < 0 || !mf || !df || !mgr) if (id < 0 || !mf || !df || !ct)
return; // error! return; // error!
QWriteLocker locker(&mgr->customTypesLock); QWriteLocker locker(customTypesLock());
QVector<QDBusCustomTypeInfo> &ct = mgr->customTypes; if (id >= ct->size())
registerMarshallOperatorsNoLock(ct, id, mf, df); ct->resize(id + 1);
} QDBusCustomTypeInfo &info = (*ct)[id];
static void registerMarshallOperatorsNoLock(QVector<QDBusCustomTypeInfo> &ct, int id,
QDBusMetaType::MarshallFunction mf,
QDBusMetaType::DemarshallFunction df)
{
if (id >= ct.size())
ct.resize(id + 1);
QDBusCustomTypeInfo &info = ct[id];
info.marshall = mf; info.marshall = mf;
info.demarshall = df; info.demarshall = df;
} }
@ -236,16 +241,12 @@ bool QDBusMetaType::marshall(QDBusArgument &arg, int id, const void *data)
MarshallFunction mf; MarshallFunction mf;
{ {
const QDBusMetaTypeId *mgr = QDBusMetaTypeId::instance(); QReadLocker locker(customTypesLock());
if (!mgr) QVector<QDBusCustomTypeInfo> *ct = customTypes();
return false; // shutting down if (id >= ct->size())
QReadLocker locker(&mgr->customTypesLock);
const QVector<QDBusCustomTypeInfo> &ct = mgr->customTypes;
if (id >= ct.size())
return false; // non-existent return false; // non-existent
const QDBusCustomTypeInfo &info = ct.at(id); const QDBusCustomTypeInfo &info = (*ct).at(id);
if (!info.marshall) { if (!info.marshall) {
mf = 0; // make gcc happy mf = 0; // make gcc happy
return false; return false;
@ -269,16 +270,12 @@ bool QDBusMetaType::demarshall(const QDBusArgument &arg, int id, void *data)
DemarshallFunction df; DemarshallFunction df;
{ {
const QDBusMetaTypeId *mgr = QDBusMetaTypeId::instance(); QReadLocker locker(customTypesLock());
if (!mgr) QVector<QDBusCustomTypeInfo> *ct = customTypes();
return false; // shutting down if (id >= ct->size())
QReadLocker locker(&mgr->customTypesLock);
const QVector<QDBusCustomTypeInfo> &ct = mgr->customTypes;
if (id >= ct.size())
return false; // non-existent return false; // non-existent
const QDBusCustomTypeInfo &info = ct.at(id); const QDBusCustomTypeInfo &info = (*ct).at(id);
if (!info.demarshall) { if (!info.demarshall) {
df = 0; // make gcc happy df = 0; // make gcc happy
return false; return false;
@ -437,11 +434,7 @@ const char *QDBusMetaType::typeToSignature(int type)
DBUS_TYPE_BYTE_AS_STRING; // ay DBUS_TYPE_BYTE_AS_STRING; // ay
} }
// try the database QDBusMetaTypeId::init();
QDBusMetaTypeId *mgr = QDBusMetaTypeId::instance();
if (!mgr)
return Q_NULLPTR; // shutting down
if (type == QDBusMetaTypeId::variant()) if (type == QDBusMetaTypeId::variant())
return DBUS_TYPE_VARIANT_AS_STRING; return DBUS_TYPE_VARIANT_AS_STRING;
else if (type == QDBusMetaTypeId::objectpath()) else if (type == QDBusMetaTypeId::objectpath())
@ -451,13 +444,14 @@ const char *QDBusMetaType::typeToSignature(int type)
else if (type == QDBusMetaTypeId::unixfd()) else if (type == QDBusMetaTypeId::unixfd())
return DBUS_TYPE_UNIX_FD_AS_STRING; return DBUS_TYPE_UNIX_FD_AS_STRING;
// try the database
QVector<QDBusCustomTypeInfo> *ct = customTypes();
{ {
QReadLocker locker(&mgr->customTypesLock); QReadLocker locker(customTypesLock());
const QVector<QDBusCustomTypeInfo> &ct = mgr->customTypes; if (type >= ct->size())
if (type >= ct.size())
return 0; // type not registered with us return 0; // type not registered with us
const QDBusCustomTypeInfo &info = ct.at(type); const QDBusCustomTypeInfo &info = (*ct).at(type);
if (!info.signature.isNull()) if (!info.signature.isNull())
return info.signature; return info.signature;
@ -474,9 +468,8 @@ const char *QDBusMetaType::typeToSignature(int type)
QByteArray signature = QDBusArgumentPrivate::createSignature(type); QByteArray signature = QDBusArgumentPrivate::createSignature(type);
// re-acquire lock // re-acquire lock
QWriteLocker locker(&mgr->customTypesLock); QWriteLocker locker(customTypesLock());
QVector<QDBusCustomTypeInfo> &ct = mgr->customTypes; info = &(*ct)[type];
info = &ct[type];
info->signature = signature; info->signature = signature;
} }
return info->signature; return info->signature;

View File

@ -1,7 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2016 The Qt Company Ltd. ** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the QtDBus module of the Qt Toolkit. ** This file is part of the QtDBus module of the Qt Toolkit.
@ -61,27 +60,10 @@
#include <qdbuserror.h> #include <qdbuserror.h>
#include <qdbusunixfiledescriptor.h> #include <qdbusunixfiledescriptor.h>
#include <qbytearray.h>
#include <qreadwritelock.h>
#include <qvector.h>
#ifndef QT_NO_DBUS #ifndef QT_NO_DBUS
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QDBusCustomTypeInfo
{
public:
QDBusCustomTypeInfo() : signature(), marshall(0), demarshall(0)
{ }
// Suggestion:
// change 'signature' to char* and make QDBusCustomTypeInfo a Movable type
QByteArray signature;
QDBusMetaType::MarshallFunction marshall;
QDBusMetaType::DemarshallFunction demarshall;
};
struct QDBusMetaTypeId struct QDBusMetaTypeId
{ {
static int message(); // QDBusMessage static int message(); // QDBusMessage
@ -92,14 +74,7 @@ struct QDBusMetaTypeId
static int error(); // QDBusError static int error(); // QDBusError
static int unixfd(); // QDBusUnixFileDescriptor static int unixfd(); // QDBusUnixFileDescriptor
static void init() { instance(); } static void init();
static QDBusMetaTypeId *instance();
mutable QReadWriteLock customTypesLock;
QVector<QDBusCustomTypeInfo> customTypes;
protected:
QDBusMetaTypeId();
}; };
inline int QDBusMetaTypeId::message() inline int QDBusMetaTypeId::message()

View File

@ -144,9 +144,8 @@ int qDBusParametersForMethod(const QMetaMethod &mm, QVector<int> &metaTypes, QSt
int qDBusParametersForMethod(const QList<QByteArray> &parameterTypes, QVector<int>& metaTypes, QString &errorMsg) int qDBusParametersForMethod(const QList<QByteArray> &parameterTypes, QVector<int>& metaTypes, QString &errorMsg)
{ {
QDBusMetaTypeId::init();
metaTypes.clear(); metaTypes.clear();
if (!QDBusMetaTypeId::instance())
return -1;
metaTypes.append(0); // return type metaTypes.append(0); // return type
int inputCount = 0; int inputCount = 0;