@@ -24,7 +24,11 @@ LiveTileData::LiveTileData(const TileID& id_,
|
||||
state = State::loaded;
|
||||
}
|
||||
|
||||
LiveTileData::~LiveTileData() {}
|
||||
LiveTileData::~LiveTileData() {
|
||||
// Cancel in most derived class destructor so that worker tasks are joined before
|
||||
// any member data goes away.
|
||||
cancel();
|
||||
}
|
||||
|
||||
void LiveTileData::parse() {
|
||||
if (state != State::loaded) {
|
||||
|
||||
@@ -9,6 +9,9 @@ RasterTileData::RasterTileData(const TileID& id_, TexturePool &texturePool,
|
||||
}
|
||||
|
||||
RasterTileData::~RasterTileData() {
|
||||
// Cancel in most derived class destructor so that worker tasks are joined before
|
||||
// any member data goes away.
|
||||
cancel();
|
||||
}
|
||||
|
||||
void RasterTileData::parse() {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/ptr.hpp>
|
||||
#include <mbgl/util/work_request.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
@@ -21,8 +22,7 @@ class StyleLayer;
|
||||
class Request;
|
||||
class Worker;
|
||||
|
||||
class TileData : public std::enable_shared_from_this<TileData>,
|
||||
private util::noncopyable {
|
||||
class TileData : private util::noncopyable {
|
||||
public:
|
||||
enum class State {
|
||||
invalid,
|
||||
@@ -60,6 +60,8 @@ protected:
|
||||
Request *req = nullptr;
|
||||
std::string data;
|
||||
|
||||
WorkRequest workRequest;
|
||||
|
||||
// Contains the tile ID string for painting debug information.
|
||||
DebugFontBuffer debugFontBuffer;
|
||||
|
||||
|
||||
@@ -28,6 +28,9 @@ VectorTileData::VectorTileData(const TileID& id_,
|
||||
}
|
||||
|
||||
VectorTileData::~VectorTileData() {
|
||||
// Cancel in most derived class destructor so that worker tasks are joined before
|
||||
// any member data goes away.
|
||||
cancel();
|
||||
glyphAtlas.removeGlyphs(reinterpret_cast<uintptr_t>(this));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user