prevent possible race condition while obtaining collision-free shape ID

This commit is contained in:
Patrick Brosi 2019-05-13 15:05:34 +02:00
parent 0db43ad457
commit ee948a8810

View file

@ -242,6 +242,7 @@ void ShapeBuilder::shape(pfaedle::netgraph::Graph* ng) {
for (auto t : clusters[i]) { for (auto t : clusters[i]) {
if (_cfg.evaluate && _evalFeed && _ecoll) { if (_cfg.evaluate && _evalFeed && _ecoll) {
std::lock_guard<std::mutex> guard(_shpMutex);
_ecoll->add(t, _evalFeed->getShapes().get(t->getShape()), shp, _ecoll->add(t, _evalFeed->getShapes().get(t->getShape()), shp,
distances); distances);
} }
@ -249,6 +250,7 @@ void ShapeBuilder::shape(pfaedle::netgraph::Graph* ng) {
if (!t->getShape().empty() && shpUsage[t->getShape()] > 0) { if (!t->getShape().empty() && shpUsage[t->getShape()] > 0) {
shpUsage[t->getShape()]--; shpUsage[t->getShape()]--;
if (shpUsage[t->getShape()] == 0) { if (shpUsage[t->getShape()] == 0) {
std::lock_guard<std::mutex> guard(_shpMutex);
_feed->getShapes().remove(t->getShape()); _feed->getShapes().remove(t->getShape());
} }
} }
@ -289,7 +291,6 @@ void ShapeBuilder::setShape(Trip* t, const ad::cppgtfs::gtfs::Shape& s,
} }
std::lock_guard<std::mutex> guard(_shpMutex); std::lock_guard<std::mutex> guard(_shpMutex);
// TODO(patrick):
t->setShape(_feed->getShapes().add(s)); t->setShape(_feed->getShapes().add(s));
} }