diff options
Diffstat (limited to 'common/threadboundary.cpp')
-rw-r--r-- | common/threadboundary.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/common/threadboundary.cpp b/common/threadboundary.cpp index 705009b..22864dd 100644 --- a/common/threadboundary.cpp +++ b/common/threadboundary.cpp | |||
@@ -19,6 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include "threadboundary.h" | 21 | #include "threadboundary.h" |
22 | #include <QThread> | ||
22 | 23 | ||
23 | Q_DECLARE_METATYPE(std::function<void()>); | 24 | Q_DECLARE_METATYPE(std::function<void()>); |
24 | 25 | ||
@@ -39,7 +40,11 @@ void ThreadBoundary::callInMainThread(std::function<void()> f) | |||
39 | * than the target thread is able to execute the function calls. In that case any captures will equally pile up, resulting | 40 | * than the target thread is able to execute the function calls. In that case any captures will equally pile up, resulting |
40 | * in significant memory usage i.e. due to Emitter::addHandler calls that each capture a domain object. | 41 | * in significant memory usage i.e. due to Emitter::addHandler calls that each capture a domain object. |
41 | */ | 42 | */ |
42 | QMetaObject::invokeMethod(this, "runInMainThread", Qt::QueuedConnection, QGenericReturnArgument(), Q_ARG(std::function<void()>, f)); | 43 | if (QThread::currentThread() == this->thread()) { |
44 | f(); | ||
45 | } else { | ||
46 | QMetaObject::invokeMethod(this, "runInMainThread", Qt::QueuedConnection, QGenericReturnArgument(), Q_ARG(std::function<void()>, f)); | ||
47 | } | ||
43 | } | 48 | } |
44 | 49 | ||
45 | void ThreadBoundary::runInMainThread(std::function<void()> f) | 50 | void ThreadBoundary::runInMainThread(std::function<void()> f) |