summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/util/thread.hpp15
-rw-r--r--src/mbgl/util/worker.cpp18
2 files changed, 18 insertions, 15 deletions
diff --git a/src/mbgl/util/thread.hpp b/src/mbgl/util/thread.hpp
index 31a56a4834..91eef745fa 100644
--- a/src/mbgl/util/thread.hpp
+++ b/src/mbgl/util/thread.hpp
@@ -30,20 +30,23 @@ public:
Thread(const ThreadContext&, Args&&... args);
~Thread();
- // Invoke object->fn(args...) in the runloop thread.
+ // Invoke object->fn(args...) asynchronously.
template <typename Fn, class... Args>
void invoke(Fn fn, Args&&... args) {
loop->invoke(bind(fn), std::forward<Args>(args)...);
}
- // Invoke object->fn(args...) in the runloop thread, then invoke callback(result) in the current thread.
- template <typename Fn, class Cb, class... Args>
+ // Invoke object->fn(args...) asynchronously. The final argument to fn must be a callback.
+ // The provided callback is wrapped such that it is invoked, in the current thread (which
+ // must have a RunLoop), once for each time the invocation of fn invokes the wrapper, each
+ // time forwarding the passed arguments, until such time as the AsyncRequest is cancelled.
+ template <typename Fn, class... Args>
std::unique_ptr<AsyncRequest>
- invokeWithCallback(Fn fn, Cb&& callback, Args&&... args) {
- return loop->invokeWithCallback(bind(fn), callback, std::forward<Args>(args)...);
+ invokeWithCallback(Fn fn, Args&&... args) {
+ return loop->invokeWithCallback(bind(fn), std::forward<Args>(args)...);
}
- // Invoke object->fn(args...) in the runloop thread, and wait for the result.
+ // Invoke object->fn(args...) asynchronously, but wait for the result.
template <typename Fn, class... Args>
auto invokeSync(Fn fn, Args&&... args) {
using R = std::result_of_t<Fn(Object, Args&&...)>;
diff --git a/src/mbgl/util/worker.cpp b/src/mbgl/util/worker.cpp
index e05a5cf837..f28e6e17b8 100644
--- a/src/mbgl/util/worker.cpp
+++ b/src/mbgl/util/worker.cpp
@@ -84,8 +84,8 @@ Worker::parseRasterTile(std::unique_ptr<RasterBucket> bucket,
const std::shared_ptr<const std::string> data,
std::function<void(RasterTileParseResult)> callback) {
current = (current + 1) % threads.size();
- return threads[current]->invokeWithCallback(&Worker::Impl::parseRasterTile, callback, bucket,
- data);
+ return threads[current]->invokeWithCallback(&Worker::Impl::parseRasterTile, bucket,
+ data, callback);
}
std::unique_ptr<AsyncRequest>
@@ -95,8 +95,8 @@ Worker::parseGeometryTile(TileWorker& worker,
PlacementConfig config,
std::function<void(TileParseResult)> callback) {
current = (current + 1) % threads.size();
- return threads[current]->invokeWithCallback(&Worker::Impl::parseGeometryTile, callback, &worker,
- std::move(layers), std::move(tileData), config);
+ return threads[current]->invokeWithCallback(&Worker::Impl::parseGeometryTile, &worker,
+ std::move(layers), std::move(tileData), config, callback);
}
std::unique_ptr<AsyncRequest>
@@ -105,7 +105,7 @@ Worker::parsePendingGeometryTileLayers(TileWorker& worker,
std::function<void(TileParseResult)> callback) {
current = (current + 1) % threads.size();
return threads[current]->invokeWithCallback(&Worker::Impl::parsePendingGeometryTileLayers,
- callback, &worker, config);
+ &worker, config, callback);
}
std::unique_ptr<AsyncRequest>
@@ -114,8 +114,8 @@ Worker::redoLayout(TileWorker& worker,
PlacementConfig config,
std::function<void(TileParseResult)> callback) {
current = (current + 1) % threads.size();
- return threads[current]->invokeWithCallback(&Worker::Impl::redoLayout, callback, &worker,
- std::move(layers), config);
+ return threads[current]->invokeWithCallback(&Worker::Impl::redoLayout, &worker,
+ std::move(layers), config, callback);
}
std::unique_ptr<AsyncRequest>
@@ -124,8 +124,8 @@ Worker::redoPlacement(TileWorker& worker,
PlacementConfig config,
std::function<void(std::unique_ptr<CollisionTile>)> callback) {
current = (current + 1) % threads.size();
- return threads[current]->invokeWithCallback(&Worker::Impl::redoPlacement, callback, &worker,
- &buckets, config);
+ return threads[current]->invokeWithCallback(&Worker::Impl::redoPlacement, &worker,
+ &buckets, config, callback);
}
} // end namespace mbgl