Join worker tasks before destroying TileData

Fixes #1309
This commit is contained in:
John Firebaugh
2015-05-02 13:31:56 -04:00
parent e476fcbf3b
commit 5c7867f435
11 changed files with 111 additions and 40 deletions

View File

@@ -55,21 +55,11 @@ void TileData::cancel() {
env.cancelRequest(req);
req = nullptr;
}
if (workRequest) {
workRequest.join();
}
}
void TileData::reparse(Worker& worker, std::function<void()> callback) {
util::ptr<TileData> tile = shared_from_this();
worker.send(
[this]() {
EnvironmentScope scope(env, ThreadType::TileWorker, "TileWorker_" + name);
parse();
},
[tile, callback]() {
// `tile` is bound in this lambda to ensure that if it's the last owning pointer,
// destruction happens on the map thread, not the worker thread. It is _not_ bound
// in the above lambda, because we do not want the possibility to arise that the
// after callback could execute and release the penultimate reference before the
// work callback has been destructed.
callback();
});
workRequest = worker.send([this] { parse(); }, callback);
}