]> git.sesse.net Git - nageru/blobdiff - shared/post_to_main_thread.h
Make the number of cameras dynamic as the frames come in.
[nageru] / shared / post_to_main_thread.h
index 0462c7b67ab55f232f4de9c556e51033c38541ca..080ed51e5f4fc2279d9a1f60d73192e592167e3c 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <QApplication>
 #include <QObject>
+#include <future>
 #include <memory>
 
 // http://stackoverflow.com/questions/21646467/how-to-execute-a-functor-in-a-given-thread-in-qt-gcd-style
@@ -13,4 +14,14 @@ static inline void post_to_main_thread(F &&fun)
        QObject::connect(&signalSource, &QObject::destroyed, qApp, std::move(fun));
 }
 
+template<typename F>
+static inline void post_to_main_thread_and_wait(F &&fun)
+{
+       std::promise<void> done_promise;
+       std::future<void> done = done_promise.get_future();
+       post_to_main_thread(std::move(fun));
+       post_to_main_thread([&done_promise] { done_promise.set_value(); });
+       done.wait();
+}
+
 #endif  // !defined(_POST_TO_MAIN_THREAD_H)