Remove indirection
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user