From daeb334039e9dcc01485995f53552749131a06b7 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 28 Apr 2016 15:00:58 -0700 Subject: Merge the QDBusMetaType's custom information to QDBusConnectionManager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows us to get rid of two Q_GLOBAL_STATIC in QtDBus, which means fewer opportunities for screwing up the order of destruction. And since QDBusConnectionManager now ensures that the types are initialized, we don't need to re-initialize them everywhere. The Q_GLOBAL_STATIC for QDBusConnectionManager ensures the proper thread-safe locking, so we don't need to lock for every type that we're trying to register. This should make things faster. But as a side-effect, trying to register a D-Bus metatype will cause the QDBusConnectionManager thread to start too. Change-Id: Ifea6e497f11a461db432ffff1449a4e535234485 Reviewed-by: René J.V. Bertin Reviewed-by: Anton Kudryavtsev Reviewed-by: Thiago Macieira Reviewed-by: Lars Knoll --- src/dbus/qdbusmetatype_p.h | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/dbus/qdbusmetatype_p.h') diff --git a/src/dbus/qdbusmetatype_p.h b/src/dbus/qdbusmetatype_p.h index 1aa11552df..1f7e61318a 100644 --- a/src/dbus/qdbusmetatype_p.h +++ b/src/dbus/qdbusmetatype_p.h @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2016 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtDBus module of the Qt Toolkit. @@ -60,10 +61,27 @@ #include #include +#include +#include +#include + #ifndef QT_NO_DBUS 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 { static int message(); // QDBusMessage @@ -74,7 +92,14 @@ struct QDBusMetaTypeId static int error(); // QDBusError static int unixfd(); // QDBusUnixFileDescriptor - static void init(); + static void init() { instance(); } + static QDBusMetaTypeId *instance(); + + mutable QReadWriteLock customTypesLock; + QVector customTypes; + +protected: + QDBusMetaTypeId(); }; inline int QDBusMetaTypeId::message() -- cgit v1.2.3