Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move SendEvent/SendMessage processing out of UI thread.
When I re-enabled the SendReceiveStringList UI blocking debugging it turned out
almost all the UI blocking for MythProto was caused by processing asynchronous
events via a synchronous MythProto call in the UI thread. This creates a runable
to process these outside the UI thread so we get a much smoother UI experience.
  • Loading branch information
daniel-kristjansson committed Nov 1, 2012
1 parent b72c3ae commit 9757830
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions mythtv/libs/libmythbase/mythcorecontext.cpp
Expand Up @@ -1035,33 +1035,54 @@ bool MythCoreContext::SendReceiveStringList(
return ok;
}

class SendAsyncMessage : public QRunnable
{
public:
SendAsyncMessage(const QString &msg, const QStringList &extra) :
m_message(msg), m_extraData(extra)
{
}

SendAsyncMessage(const QString &msg) : m_message(msg) { }

void run(void)
{
QStringList strlist("MESSAGE");
strlist << m_message;
strlist << m_extraData;
gCoreContext->SendReceiveStringList(strlist);
}

private:
QString m_message;
QStringList m_extraData;
};

void MythCoreContext::SendMessage(const QString &message)
{
if (IsBackend())
{
dispatch(MythEvent(message));
return;
}

QStringList strlist( "MESSAGE" );
strlist << message;

SendReceiveStringList(strlist);
else
{
MThreadPool::globalInstance()->start(
new SendAsyncMessage(message), "SendMessage");
}
}

void MythCoreContext::SendEvent(const MythEvent &event)
{
if (IsBackend())
{
dispatch(event);
return;
}

QStringList strlist( "MESSAGE" );
strlist << event.Message();
strlist << event.ExtraDataList();

SendReceiveStringList(strlist);
else
{
MThreadPool::globalInstance()->start(
new SendAsyncMessage(event.Message(), event.ExtraDataList()),
"SendEvent");
}
}

void MythCoreContext::SendSystemEvent(const QString &msg)
Expand Down

0 comments on commit 9757830

Please sign in to comment.