From e5125013a2661b30f21323f1a3f925103e8d589f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 22 Dec 2015 09:25:18 +0100 Subject: Threadboundary cleanup --- common/threadboundary.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'common/threadboundary.cpp') diff --git a/common/threadboundary.cpp b/common/threadboundary.cpp index 48fd11a..238f5b4 100644 --- a/common/threadboundary.cpp +++ b/common/threadboundary.cpp @@ -23,10 +23,30 @@ Q_DECLARE_METATYPE(std::function); namespace async { -ThreadBoundary::ThreadBoundary(): QObject() { qRegisterMetaType >("std::function"); } +ThreadBoundary::ThreadBoundary() + : QObject() +{ + qRegisterMetaType >("std::function"); +} + ThreadBoundary:: ~ThreadBoundary() { } +void ThreadBoundary::callInMainThread(std::function f) +{ + /* + * This implementation causes lambdas to pile up if the target thread is the same as the caller thread, or the caller thread calls faster + * than the target thread is able to execute the function calls. In that case any captures will equally pile up, resulting + * in significant memory usage i.e. due to Emitter::addHandler calls that each capture a domain object. + */ + QMetaObject::invokeMethod(this, "runInMainThread", Qt::QueuedConnection, QGenericReturnArgument(), Q_ARG(std::function, f)); +} + +void ThreadBoundary::runInMainThread(std::function f) +{ + f(); +} + } -- cgit v1.2.3