summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-04-09 11:10:51 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-04-09 11:10:51 -0700
commit0b779eaa8b96a65d5b97df7ad468e0380f50703f (patch)
treead85227f0d25727fc1f88ac31525a89b2b9e911d /src
parent691756d7dd31c4be789840a6c9881d299176be3c (diff)
downloadqtlocation-mapboxgl-0b779eaa8b96a65d5b97df7ad468e0380f50703f.tar.gz
Remove unnecessary use of weak_ptr
The request callback runs in the same thread as ~TileData, and is not run if the request is cancelled. So either ~TileData runs first and cancels the request, or the callback runs first, before TileData is destructed. Therefore the weak pointer and lock() check is unnecessary; `this` can be used instead.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/tile_data.cpp31
1 files changed, 10 insertions, 21 deletions
diff --git a/src/mbgl/map/tile_data.cpp b/src/mbgl/map/tile_data.cpp
index fdec759938..74993ff52a 100644
--- a/src/mbgl/map/tile_data.cpp
+++ b/src/mbgl/map/tile_data.cpp
@@ -20,9 +20,7 @@ TileData::TileData(const TileID& id_, const SourceInfo& source_)
}
TileData::~TileData() {
- if (req) {
- env.cancelRequest(req);
- }
+ cancel();
}
const std::string TileData::toString() const {
@@ -33,28 +31,19 @@ void TileData::request(uv::worker &worker, float pixelRatio, std::function<void(
std::string url = source.tileURL(id, pixelRatio);
state = State::loading;
- std::weak_ptr<TileData> weak_tile = shared_from_this();
- req = env.request({ Resource::Kind::Tile, url }, [weak_tile, url, callback, &worker](const Response &res) {
- util::ptr<TileData> tile = weak_tile.lock();
- if (!tile || tile->state == State::obsolete) {
- // noop. Tile is obsolete and we're now just waiting for the refcount
- // to drop to zero for destruction.
+ req = env.request({ Resource::Kind::Tile, url }, [url, callback, &worker, this](const Response &res) {
+ req = nullptr;
+
+ if (res.status != Response::Successful) {
+ Log::Error(Event::HttpRequest, "[%s] tile loading failed: %s", url.c_str(), res.message.c_str());
return;
}
- // Clear the request object.
- tile->req = nullptr;
-
- if (res.status == Response::Successful) {
- tile->state = State::loaded;
-
- tile->data = res.data;
+ state = State::loaded;
+ data = res.data;
- // Schedule tile parsing in another thread
- tile->reparse(worker, callback);
- } else {
- Log::Error(Event::HttpRequest, "[%s] tile loading failed: %s", url.c_str(), res.message.c_str());
- }
+ // Schedule tile parsing in another thread
+ reparse(worker, callback);
});
}