summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-06-04 19:07:48 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-07-01 15:21:09 -0700
commit875ef979be0140332ab219e422022ccb38b99a1e (patch)
tree828c8be75f1576b98c2106c327f2b4681202dc8c /src
parent217c376291967aecd7c8cc26e485e3a4fe09ee60 (diff)
downloadqtlocation-mapboxgl-875ef979be0140332ab219e422022ccb38b99a1e.tar.gz
Remove indirection
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/live_tile_data.cpp19
-rw-r--r--src/mbgl/map/tile_data.hpp2
-rw-r--r--src/mbgl/map/vector_tile_data.cpp37
-rw-r--r--src/mbgl/map/vector_tile_data.hpp27
4 files changed, 17 insertions, 68 deletions
diff --git a/src/mbgl/map/live_tile_data.cpp b/src/mbgl/map/live_tile_data.cpp
index 74d939f35a..ab6f5d983f 100644
--- a/src/mbgl/map/live_tile_data.cpp
+++ b/src/mbgl/map/live_tile_data.cpp
@@ -14,20 +14,18 @@ LiveTileData::LiveTileData(const TileID& id_,
const SourceInfo& source_,
float angle_,
bool collisionDebug_)
- : VectorTileData::VectorTileData(id_, style_, source_, angle_, collisionDebug_),
+ : VectorTileData(id_, style_, source_, angle_, collisionDebug_),
annotationManager(annotationManager_) {
- // live features are always ready
- setState(State::loaded);
+ // live features are always loaded
+ state = State::loaded;
}
LiveTileData::~LiveTileData() {
- // Cancel in most derived class destructor so that worker tasks are joined before
- // any member data goes away.
cancel();
}
bool LiveTileData::reparse(Worker&, std::function<void()> callback) {
- if (!mayStartParsing()) {
+ if (parsing.test_and_set(std::memory_order_acquire)) {
return false;
}
@@ -39,7 +37,7 @@ bool LiveTileData::reparse(Worker&, std::function<void()> callback) {
const LiveTile* tile = annotationManager.getTile(id);
if (!tile) {
- setState(State::parsed);
+ state = State::parsed;
return;
}
@@ -56,12 +54,13 @@ bool LiveTileData::reparse(Worker&, std::function<void()> callback) {
if (getState() == TileData::State::obsolete) {
return;
} else if (result.is<State>()) {
- setState(result.get<State>());
+ state = result.get<State>();
} else {
- setError(result.get<std::string>());
+ error = result.get<std::string>();
+ state = State::obsolete;
}
- endParsing();
+ parsing.clear(std::memory_order_release);
}, callback);
return true;
diff --git a/src/mbgl/map/tile_data.hpp b/src/mbgl/map/tile_data.hpp
index 9006eb6ad8..5ed4ef4fd4 100644
--- a/src/mbgl/map/tile_data.hpp
+++ b/src/mbgl/map/tile_data.hpp
@@ -77,7 +77,7 @@ public:
// Schedule a tile reparse on a worker thread and call the callback on
// completion. It will return true if the work was schedule or false it was
// not, which can occur if the tile is already being parsed by another
- // worker (see "mayStartParsing()").
+ // worker.
virtual bool reparse(Worker&,
std::function<void ()> callback) = 0;
diff --git a/src/mbgl/map/vector_tile_data.cpp b/src/mbgl/map/vector_tile_data.cpp
index 0b241d722a..171fc7cf7a 100644
--- a/src/mbgl/map/vector_tile_data.cpp
+++ b/src/mbgl/map/vector_tile_data.cpp
@@ -34,8 +34,6 @@ 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();
}
@@ -52,7 +50,8 @@ void VectorTileData::request(Worker&,
if (res.status != Response::Successful) {
std::stringstream message;
message << "Failed to load [" << url << "]: " << res.message;
- setError(message.str());
+ error = message.str();
+ state = State::obsolete;
callback();
return;
}
@@ -65,7 +64,7 @@ void VectorTileData::request(Worker&,
}
bool VectorTileData::reparse(Worker&, std::function<void()> callback) {
- if (!mayStartParsing()) {
+ if (parsing.test_and_set(std::memory_order_acquire)) {
return false;
}
@@ -88,12 +87,13 @@ bool VectorTileData::reparse(Worker&, std::function<void()> callback) {
if (getState() == TileData::State::obsolete) {
return;
} else if (result.is<State>()) {
- setState(result.get<State>());
+ state = result.get<State>();
} else {
- setError(result.get<std::string>());
+ error = result.get<std::string>();
+ state = State::obsolete;
}
- endParsing();
+ parsing.clear(std::memory_order_release);
}, callback);
return true;
@@ -111,16 +111,6 @@ size_t VectorTileData::countBuckets() const {
return workerData.countBuckets();
}
-void VectorTileData::setState(const State& state_) {
- assert(!isImmutable());
-
- state = state_;
-
- if (isImmutable()) {
- workerData.collision->reset(0, 0);
- }
-}
-
void VectorTileData::redoPlacement() {
redoPlacement(lastAngle, lastCollisionDebug);
}
@@ -162,16 +152,3 @@ void VectorTileData::cancel() {
}
workRequest.reset();
}
-
-bool VectorTileData::mayStartParsing() {
- return !parsing.test_and_set(std::memory_order_acquire);
-}
-
-void VectorTileData::endParsing() {
- parsing.clear(std::memory_order_release);
-}
-
-void VectorTileData::setError(const std::string& message) {
- error = message;
- setState(State::obsolete);
-}
diff --git a/src/mbgl/map/vector_tile_data.hpp b/src/mbgl/map/vector_tile_data.hpp
index bb0e316c18..4157a19d92 100644
--- a/src/mbgl/map/vector_tile_data.hpp
+++ b/src/mbgl/map/vector_tile_data.hpp
@@ -39,44 +39,17 @@ public:
void cancel() override;
protected:
- // We let subclasses override setState() so they
- // can intercept the state change and react accordingly.
- void setState(const State&);
-
- // Set the internal parsing state to true so we prevent
- // multiple workers to parse the same tile in parallel,
- // which can happen if the tile is in the "partial" state.
- // It will return true if is possible to start pasing the
- // tile or false if not (so some other worker is already
- // parsing the tile).
- bool mayStartParsing();
-
- void endParsing();
-
- // Error message to be set in case of request
- // and parsing errors.
- void setError(const std::string& message);
-
void redoPlacement();
const SourceInfo& source;
-
Request *req = nullptr;
std::string data;
-
Worker& worker;
TileWorker workerData;
-
std::unique_ptr<WorkRequest> workRequest;
std::atomic_flag parsing = ATOMIC_FLAG_INIT;
private:
- // Returns true if the TileData is in a final state and we cannot
- // make changes to it anymore.
- inline bool isImmutable() const {
- return state == State::parsed || state == State::obsolete;
- }
-
float lastAngle = 0;
float currentAngle;
bool lastCollisionDebug = 0;