diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2015-03-30 19:34:03 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2015-09-15 02:08:54 +0000 |
commit | cc5ab92cd9e06511f7a65cc3195f01a730591768 (patch) | |
tree | 02491416952098edd67c4bff99311978df836bc8 /src/dbus/qdbusintegrator.cpp | |
parent | d8148edb2318a0cd57ac704c105960728461a19a (diff) |
Make QDBusConnectionPrivate::getNameOwnerNoCache work in our thread
In two commits, we will attempt to call this function from the manager
thread, so we need to be sure this function works from there. Right now,
it would deadlock in QDBusPendingCallPrivate::waitForFinished(), inside
QDBusConnectionPrivate::sendWithReply().
The solution is simple: expand sendWithReply to the sendWithReplyAsync
function it calls anyway, but tell the internal DBusPendingCall to
finish before we call waitForFinished().
Change-Id: Iee8cbc07c4434ce9b560ffff13d0749013d771ab
Reviewed-by: Albert Astals Cid <aacid@kde.org>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/dbus/qdbusintegrator.cpp')
-rw-r--r-- | src/dbus/qdbusintegrator.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 0a95a8e781..7370d0bbfc 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -2362,9 +2362,21 @@ QString QDBusConnectionPrivate::getNameOwnerNoCache(const QString &serviceName) QStringLiteral("GetNameOwner")); QDBusMessagePrivate::setParametersValidated(msg, true); msg << serviceName; - QDBusMessage reply = sendWithReply(msg, QDBus::Block); - if (reply.type() == QDBusMessage::ReplyMessage) - return reply.arguments().at(0).toString(); + + QDBusPendingCallPrivate *pcall = sendWithReplyAsync(msg, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR); + if (thread() == QThread::currentThread()) { + // this function may be called in our own thread and + // QDBusPendingCallPrivate::waitForFinished() would deadlock there + q_dbus_pending_call_block(pcall->pending); + } + pcall->waitForFinished(); + msg = pcall->replyMessage; + + if (!pcall->ref.deref()) + delete pcall; + + if (msg.type() == QDBusMessage::ReplyMessage) + return msg.arguments().at(0).toString(); return QString(); } |