summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-05-01 12:07:34 -0400
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-05-01 12:07:34 -0400
commit51c069502880e38a6dabf520c032fd6f293ee744 (patch)
tree1406fcc0c1200e581e04ee3565136143a4f239f8 /src
parent09496737eb9bbb5321982c961d21babbd0dc5994 (diff)
downloadqtlocation-mapboxgl-51c069502880e38a6dabf520c032fd6f293ee744.tar.gz
Replace unsafe use of future with packaged_task
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/util/thread.hpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/mbgl/util/thread.hpp b/src/mbgl/util/thread.hpp
index 850b35c9e9..415bda38d8 100644
--- a/src/mbgl/util/thread.hpp
+++ b/src/mbgl/util/thread.hpp
@@ -62,19 +62,19 @@ public:
// Invoke object->fn(args...) in the runloop thread, and wait for the result.
template <class R, typename Fn, class... Args>
R invokeSync(Fn fn, Args&&... args) {
- std::promise<R> promise;
- auto bound = std::bind(fn, object, args...);
- loop->invoke([&] { promise.set_value(bound()); } );
- return promise.get_future().get();
+ std::packaged_task<R ()> task(std::bind(fn, object, args...));
+ std::future<R> future = task.get_future();
+ loop->invoke(std::move(task));
+ return future.get();
}
// Invoke object->fn(args...) in the runloop thread, and wait for it to complete.
template <typename Fn, class... Args>
void invokeSync(Fn fn, Args&&... args) {
- std::promise<void> promise;
- auto bound = std::bind(fn, object, args...);
- loop->invoke([&] { bound(); promise.set_value(); } );
- promise.get_future().get();
+ std::packaged_task<void ()> task(std::bind(fn, object, args...));
+ std::future<void> future = task.get_future();
+ loop->invoke(std::move(task));
+ return future.get();
}
// Join the thread, but call the given function repeatedly in the current thread