QtDBus: port all QMutexLocker users to qt_{scoped,unique}_lock
Change-Id: Ibba27351a81b0b132ce702c1dfd49d56f23bd8c1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
d603ee689f
commit
e913b690b9
@ -41,6 +41,7 @@
|
|||||||
#include <QtCore/qglobal.h>
|
#include <QtCore/qglobal.h>
|
||||||
#if QT_CONFIG(library)
|
#if QT_CONFIG(library)
|
||||||
#include <QtCore/qlibrary.h>
|
#include <QtCore/qlibrary.h>
|
||||||
|
#include <QtCore/private/qlocking_p.h>
|
||||||
#endif
|
#endif
|
||||||
#include <QtCore/qmutex.h>
|
#include <QtCore/qmutex.h>
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ bool qdbus_loadLibDBus()
|
|||||||
|
|
||||||
static bool triedToLoadLibrary = false;
|
static bool triedToLoadLibrary = false;
|
||||||
static QBasicMutex mutex;
|
static QBasicMutex mutex;
|
||||||
QMutexLocker locker(&mutex);
|
const auto locker = qt_scoped_lock(mutex);
|
||||||
|
|
||||||
QLibrary *&lib = qdbus_libdbus;
|
QLibrary *&lib = qdbus_libdbus;
|
||||||
if (triedToLoadLibrary)
|
if (triedToLoadLibrary)
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
#include <qvector.h>
|
#include <qvector.h>
|
||||||
#include <qtimer.h>
|
#include <qtimer.h>
|
||||||
#include <qthread.h>
|
#include <qthread.h>
|
||||||
|
#include <QtCore/private/qlocking_p.h>
|
||||||
|
|
||||||
#include "qdbusconnectioninterface.h"
|
#include "qdbusconnectioninterface.h"
|
||||||
#include "qdbuserror.h"
|
#include "qdbuserror.h"
|
||||||
@ -106,7 +107,7 @@ QDBusConnectionPrivate *QDBusConnectionManager::busConnection(QDBusConnection::B
|
|||||||
// (the event loop will resume delivery)
|
// (the event loop will resume delivery)
|
||||||
bool suspendedDelivery = qApp && qApp->thread() == QThread::currentThread();
|
bool suspendedDelivery = qApp && qApp->thread() == QThread::currentThread();
|
||||||
|
|
||||||
QMutexLocker lock(&defaultBusMutex);
|
const auto locker = qt_scoped_lock(defaultBusMutex);
|
||||||
if (defaultBuses[type])
|
if (defaultBuses[type])
|
||||||
return defaultBuses[type];
|
return defaultBuses[type];
|
||||||
|
|
||||||
@ -178,7 +179,7 @@ void QDBusConnectionManager::run()
|
|||||||
exec();
|
exec();
|
||||||
|
|
||||||
// cleanup:
|
// cleanup:
|
||||||
QMutexLocker locker(&mutex);
|
const auto locker = qt_scoped_lock(mutex);
|
||||||
for (QHash<QString, QDBusConnectionPrivate *>::const_iterator it = connectionHash.constBegin();
|
for (QHash<QString, QDBusConnectionPrivate *>::const_iterator it = connectionHash.constBegin();
|
||||||
it != connectionHash.constEnd(); ++it) {
|
it != connectionHash.constEnd(); ++it) {
|
||||||
QDBusConnectionPrivate *d = it.value();
|
QDBusConnectionPrivate *d = it.value();
|
||||||
@ -240,7 +241,7 @@ QDBusConnectionPrivate *QDBusConnectionManager::connectToPeer(const QString &add
|
|||||||
|
|
||||||
void QDBusConnectionManager::executeConnectionRequest(QDBusConnectionManager::ConnectionRequestData *data)
|
void QDBusConnectionManager::executeConnectionRequest(QDBusConnectionManager::ConnectionRequestData *data)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mutex);
|
const auto locker = qt_scoped_lock(mutex);
|
||||||
const QString &name = *data->name;
|
const QString &name = *data->name;
|
||||||
QDBusConnectionPrivate *&d = data->result;
|
QDBusConnectionPrivate *&d = data->result;
|
||||||
|
|
||||||
@ -428,7 +429,7 @@ QDBusConnection::QDBusConnection(const QString &name)
|
|||||||
if (name.isEmpty() || _q_manager.isDestroyed()) {
|
if (name.isEmpty() || _q_manager.isDestroyed()) {
|
||||||
d = 0;
|
d = 0;
|
||||||
} else {
|
} else {
|
||||||
QMutexLocker locker(&_q_manager()->mutex);
|
const auto locker = qt_scoped_lock(_q_manager()->mutex);
|
||||||
d = _q_manager()->connection(name);
|
d = _q_manager()->connection(name);
|
||||||
if (d)
|
if (d)
|
||||||
d->ref.ref();
|
d->ref.ref();
|
||||||
@ -537,7 +538,7 @@ QDBusConnection QDBusConnection::connectToPeer(const QString &address,
|
|||||||
void QDBusConnection::disconnectFromBus(const QString &name)
|
void QDBusConnection::disconnectFromBus(const QString &name)
|
||||||
{
|
{
|
||||||
if (_q_manager()) {
|
if (_q_manager()) {
|
||||||
QMutexLocker locker(&_q_manager()->mutex);
|
const auto locker = qt_scoped_lock(_q_manager()->mutex);
|
||||||
QDBusConnectionPrivate *d = _q_manager()->connection(name);
|
QDBusConnectionPrivate *d = _q_manager()->connection(name);
|
||||||
if (d && d->mode != QDBusConnectionPrivate::ClientMode)
|
if (d && d->mode != QDBusConnectionPrivate::ClientMode)
|
||||||
return;
|
return;
|
||||||
@ -558,7 +559,7 @@ void QDBusConnection::disconnectFromBus(const QString &name)
|
|||||||
void QDBusConnection::disconnectFromPeer(const QString &name)
|
void QDBusConnection::disconnectFromPeer(const QString &name)
|
||||||
{
|
{
|
||||||
if (_q_manager()) {
|
if (_q_manager()) {
|
||||||
QMutexLocker locker(&_q_manager()->mutex);
|
const auto locker = qt_scoped_lock(_q_manager()->mutex);
|
||||||
QDBusConnectionPrivate *d = _q_manager()->connection(name);
|
QDBusConnectionPrivate *d = _q_manager()->connection(name);
|
||||||
if (d && d->mode != QDBusConnectionPrivate::PeerMode)
|
if (d && d->mode != QDBusConnectionPrivate::PeerMode)
|
||||||
return;
|
return;
|
||||||
|
@ -49,6 +49,7 @@
|
|||||||
#include <qstringlist.h>
|
#include <qstringlist.h>
|
||||||
#include <qtimer.h>
|
#include <qtimer.h>
|
||||||
#include <qthread.h>
|
#include <qthread.h>
|
||||||
|
#include <private/qlocking_p.h>
|
||||||
|
|
||||||
#include "qdbusargument.h"
|
#include "qdbusargument.h"
|
||||||
#include "qdbusconnection_p.h"
|
#include "qdbusconnection_p.h"
|
||||||
@ -304,7 +305,7 @@ static void qDBusNewConnection(DBusServer *server, DBusConnection *connection, v
|
|||||||
q_dbus_connection_set_allow_anonymous(connection, true);
|
q_dbus_connection_set_allow_anonymous(connection, true);
|
||||||
|
|
||||||
QDBusConnectionPrivate *newConnection = new QDBusConnectionPrivate(serverConnection->parent());
|
QDBusConnectionPrivate *newConnection = new QDBusConnectionPrivate(serverConnection->parent());
|
||||||
QMutexLocker locker(&QDBusConnectionManager::instance()->mutex);
|
const auto locker = qt_scoped_lock(QDBusConnectionManager::instance()->mutex);
|
||||||
QDBusConnectionManager::instance()->setConnection(QLatin1String("QDBusServer-") + QString::number(reinterpret_cast<qulonglong>(newConnection), 16), newConnection);
|
QDBusConnectionManager::instance()->setConnection(QLatin1String("QDBusServer-") + QString::number(reinterpret_cast<qulonglong>(newConnection), 16), newConnection);
|
||||||
serverConnection->serverConnectionNames << newConnection->name;
|
serverConnection->serverConnectionNames << newConnection->name;
|
||||||
|
|
||||||
@ -1862,7 +1863,7 @@ void QDBusConnectionPrivate::processFinishedCall(QDBusPendingCallPrivate *call)
|
|||||||
{
|
{
|
||||||
QDBusConnectionPrivate *connection = const_cast<QDBusConnectionPrivate *>(call->connection);
|
QDBusConnectionPrivate *connection = const_cast<QDBusConnectionPrivate *>(call->connection);
|
||||||
|
|
||||||
QMutexLocker locker(&call->mutex);
|
auto locker = qt_unique_lock(call->mutex);
|
||||||
|
|
||||||
connection->pendingCalls.removeOne(call);
|
connection->pendingCalls.removeOne(call);
|
||||||
|
|
||||||
@ -1979,7 +1980,7 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
static bool initializedAmounts = false;
|
static bool initializedAmounts = false;
|
||||||
static QBasicMutex initializeMutex;
|
static QBasicMutex initializeMutex;
|
||||||
QMutexLocker locker(&initializeMutex);
|
auto locker = qt_unique_lock(initializeMutex);
|
||||||
|
|
||||||
if (!initializedAmounts) {
|
if (!initializedAmounts) {
|
||||||
int tmp = 0;
|
int tmp = 0;
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
#include "qcoreapplication.h"
|
#include "qcoreapplication.h"
|
||||||
#include "qcoreevent.h"
|
#include "qcoreevent.h"
|
||||||
#include <private/qobject_p.h>
|
#include <private/qobject_p.h>
|
||||||
|
#include <private/qlocking_p.h>
|
||||||
|
|
||||||
#ifndef QT_NO_DBUS
|
#ifndef QT_NO_DBUS
|
||||||
|
|
||||||
@ -232,7 +233,7 @@ void QDBusPendingCallPrivate::checkReceivedSignature()
|
|||||||
|
|
||||||
void QDBusPendingCallPrivate::waitForFinished()
|
void QDBusPendingCallPrivate::waitForFinished()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mutex);
|
const auto locker = qt_scoped_lock(mutex);
|
||||||
|
|
||||||
if (replyMessage.type() != QDBusMessage::InvalidMessage)
|
if (replyMessage.type() != QDBusMessage::InvalidMessage)
|
||||||
return; // already finished
|
return; // already finished
|
||||||
@ -330,7 +331,7 @@ bool QDBusPendingCall::isFinished() const
|
|||||||
if (!d)
|
if (!d)
|
||||||
return true; // considered finished
|
return true; // considered finished
|
||||||
|
|
||||||
QMutexLocker locker(&d->mutex);
|
const auto locker = qt_scoped_lock(d->mutex);
|
||||||
return d->replyMessage.type() != QDBusMessage::InvalidMessage;
|
return d->replyMessage.type() != QDBusMessage::InvalidMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,7 +353,7 @@ bool QDBusPendingCall::isValid() const
|
|||||||
{
|
{
|
||||||
if (!d)
|
if (!d)
|
||||||
return false;
|
return false;
|
||||||
QMutexLocker locker(&d->mutex);
|
const auto locker = qt_scoped_lock(d->mutex);
|
||||||
return d->replyMessage.type() == QDBusMessage::ReplyMessage;
|
return d->replyMessage.type() == QDBusMessage::ReplyMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,7 +370,7 @@ bool QDBusPendingCall::isError() const
|
|||||||
{
|
{
|
||||||
if (!d)
|
if (!d)
|
||||||
return true; // considered finished and an error
|
return true; // considered finished and an error
|
||||||
QMutexLocker locker(&d->mutex);
|
const auto locker = qt_scoped_lock(d->mutex);
|
||||||
return d->replyMessage.type() == QDBusMessage::ErrorMessage;
|
return d->replyMessage.type() == QDBusMessage::ErrorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,7 +385,7 @@ bool QDBusPendingCall::isError() const
|
|||||||
QDBusError QDBusPendingCall::error() const
|
QDBusError QDBusPendingCall::error() const
|
||||||
{
|
{
|
||||||
if (d) {
|
if (d) {
|
||||||
QMutexLocker locker(&d->mutex);
|
const auto locker = qt_scoped_lock(d->mutex);
|
||||||
return QDBusError(d->replyMessage);
|
return QDBusError(d->replyMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -409,7 +410,7 @@ QDBusMessage QDBusPendingCall::reply() const
|
|||||||
{
|
{
|
||||||
if (!d)
|
if (!d)
|
||||||
return QDBusMessage::createError(error());
|
return QDBusMessage::createError(error());
|
||||||
QMutexLocker locker(&d->mutex);
|
const auto locker = qt_scoped_lock(d->mutex);
|
||||||
return d->replyMessage;
|
return d->replyMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,7 +504,7 @@ QDBusPendingCallWatcher::QDBusPendingCallWatcher(const QDBusPendingCall &call, Q
|
|||||||
: QObject(*new QDBusPendingCallWatcherPrivate, parent), QDBusPendingCall(call)
|
: QObject(*new QDBusPendingCallWatcherPrivate, parent), QDBusPendingCall(call)
|
||||||
{
|
{
|
||||||
if (d) { // QDBusPendingCall::d
|
if (d) { // QDBusPendingCall::d
|
||||||
QMutexLocker locker(&d->mutex);
|
const auto locker = qt_scoped_lock(d->mutex);
|
||||||
if (!d->watcherHelper) {
|
if (!d->watcherHelper) {
|
||||||
d->watcherHelper = new QDBusPendingCallWatcherHelper;
|
d->watcherHelper = new QDBusPendingCallWatcherHelper;
|
||||||
if (d->replyMessage.type() != QDBusMessage::InvalidMessage) {
|
if (d->replyMessage.type() != QDBusMessage::InvalidMessage) {
|
||||||
|
@ -42,6 +42,8 @@
|
|||||||
#include "qdbuspendingcall_p.h"
|
#include "qdbuspendingcall_p.h"
|
||||||
#include "qdbusmetatype.h"
|
#include "qdbusmetatype.h"
|
||||||
|
|
||||||
|
#include <QtCore/private/qlocking_p.h>
|
||||||
|
|
||||||
#ifndef QT_NO_DBUS
|
#ifndef QT_NO_DBUS
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -277,7 +279,7 @@ QVariant QDBusPendingReplyData::argumentAt(int index) const
|
|||||||
void QDBusPendingReplyData::setMetaTypes(int count, const int *types)
|
void QDBusPendingReplyData::setMetaTypes(int count, const int *types)
|
||||||
{
|
{
|
||||||
Q_ASSERT(d);
|
Q_ASSERT(d);
|
||||||
QMutexLocker locker(&d->mutex);
|
const auto locker = qt_scoped_lock(d->mutex);
|
||||||
d->setMetaTypes(count, types);
|
d->setMetaTypes(count, types);
|
||||||
d->checkReceivedSignature();
|
d->checkReceivedSignature();
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,8 @@
|
|||||||
#include "qdbusconnectionmanager_p.h"
|
#include "qdbusconnectionmanager_p.h"
|
||||||
#include "qdbusutil_p.h"
|
#include "qdbusutil_p.h"
|
||||||
|
|
||||||
|
#include <QtCore/private/qlocking_p.h>
|
||||||
|
|
||||||
#ifndef QT_NO_DBUS
|
#ifndef QT_NO_DBUS
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@ -111,7 +113,7 @@ QDBusServer::~QDBusServer()
|
|||||||
{
|
{
|
||||||
QWriteLocker locker(&d->lock);
|
QWriteLocker locker(&d->lock);
|
||||||
if (QDBusConnectionManager::instance()) {
|
if (QDBusConnectionManager::instance()) {
|
||||||
QMutexLocker locker(&QDBusConnectionManager::instance()->mutex);
|
const auto locker = qt_scoped_lock(QDBusConnectionManager::instance()->mutex);
|
||||||
for (const QString &name : qAsConst(d->serverConnectionNames))
|
for (const QString &name : qAsConst(d->serverConnectionNames))
|
||||||
QDBusConnectionManager::instance()->removeConnection(name);
|
QDBusConnectionManager::instance()->removeConnection(name);
|
||||||
d->serverConnectionNames.clear();
|
d->serverConnectionNames.clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user