diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-22 09:25:18 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-22 09:25:18 +0100 |
commit | e5125013a2661b30f21323f1a3f925103e8d589f (patch) | |
tree | ddd1eeafb49f2305446e784804bc3604560d844e /common/threadboundary.cpp | |
parent | 8e6671fe6d6519f1fecf37338a3263a5b88a00d1 (diff) | |
download | sink-e5125013a2661b30f21323f1a3f925103e8d589f.tar.gz sink-e5125013a2661b30f21323f1a3f925103e8d589f.zip |
Threadboundary cleanup
Diffstat (limited to 'common/threadboundary.cpp')
-rw-r--r-- | common/threadboundary.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
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 @@ | |||
23 | Q_DECLARE_METATYPE(std::function<void()>); | 23 | Q_DECLARE_METATYPE(std::function<void()>); |
24 | 24 | ||
25 | namespace async { | 25 | namespace async { |
26 | ThreadBoundary::ThreadBoundary(): QObject() { qRegisterMetaType<std::function<void()> >("std::function<void()>"); } | 26 | ThreadBoundary::ThreadBoundary() |
27 | : QObject() | ||
28 | { | ||
29 | qRegisterMetaType<std::function<void()> >("std::function<void()>"); | ||
30 | } | ||
31 | |||
27 | ThreadBoundary:: ~ThreadBoundary() | 32 | ThreadBoundary:: ~ThreadBoundary() |
28 | { | 33 | { |
29 | } | 34 | } |
30 | 35 | ||
36 | void ThreadBoundary::callInMainThread(std::function<void()> f) | ||
37 | { | ||
38 | /* | ||
39 | * This implementation causes lambdas to pile up if the target thread is the same as the caller thread, or the caller thread calls faster | ||
40 | * than the target thread is able to execute the function calls. In that case any captures will equally pile up, resulting | ||
41 | * in significant memory usage i.e. due to Emitter::addHandler calls that each capture a domain object. | ||
42 | */ | ||
43 | QMetaObject::invokeMethod(this, "runInMainThread", Qt::QueuedConnection, QGenericReturnArgument(), Q_ARG(std::function<void()>, f)); | ||
44 | } | ||
45 | |||
46 | void ThreadBoundary::runInMainThread(std::function<void()> f) | ||
47 | { | ||
48 | f(); | ||
49 | } | ||
50 | |||
31 | } | 51 | } |
32 | 52 | ||