Skip to content

Commit cfebdcb

Browse files
committed
Simplify expire tree merging
This also fixes a (theoretical) bug introduced a bit earlier when clones were only generated for outputs that need forward depencencies. In that case the outputs and clones used in merging expire trees did not match. The bug is theoretical, because there is currently no way in osm2pgsql to create several outputs of which some need dependency management and others don't.
1 parent 9ff2540 commit cfebdcb

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/osmdata.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ struct pending_threaded_processor : public pending_processor
186186
{
187187
while (osmid_t const id = pop_id(queue, mutex)) {
188188
for (auto const &output : outputs) {
189-
output->pending_way(id);
189+
if (output) {
190+
output->pending_way(id);
191+
}
190192
}
191193
}
192194
}
@@ -196,7 +198,9 @@ struct pending_threaded_processor : public pending_processor
196198
{
197199
while (osmid_t const id = pop_id(queue, mutex)) {
198200
for (auto const &output : outputs) {
199-
output->pending_relation(id);
201+
if (output) {
202+
output->pending_relation(id);
203+
}
200204
}
201205
}
202206
}
@@ -237,6 +241,8 @@ struct pending_threaded_processor : public pending_processor
237241
for (auto const &out : m_outputs) {
238242
if (out->need_forward_dependencies()) {
239243
m_clones[i].push_back(out->clone(midq, copy_thread));
244+
} else {
245+
m_clones[i].emplace_back(nullptr);
240246
}
241247
}
242248
}
@@ -282,7 +288,9 @@ struct pending_threaded_processor : public pending_processor
282288

283289
for (auto const &clone : m_clones) {
284290
for (auto const &clone_output : clone) {
285-
clone_output->commit();
291+
if (clone_output) {
292+
clone_output->commit();
293+
}
286294
}
287295
}
288296

@@ -305,16 +313,16 @@ struct pending_threaded_processor : public pending_processor
305313
{
306314
process_queue("relation", do_rels);
307315

308-
//collect all expiry tree informations together into one
316+
// Collect expiry tree information from all clones and merge it back
317+
// into the original outputs.
309318
for (auto const &clone : m_clones) {
310-
for (output_vec_t::const_iterator
311-
original_output = m_outputs.begin(),
312-
clone_output = clone.begin();
313-
original_output != m_outputs.end() &&
314-
clone_output != clone.end();
315-
++original_output, ++clone_output) {
316-
//merge the expire tree from this threads copy of output back
317-
original_output->get()->merge_expire_trees(clone_output->get());
319+
auto it = clone.begin();
320+
for (auto const &output : m_outputs) {
321+
assert(it != clone.end());
322+
if (*it) {
323+
output->merge_expire_trees(it->get());
324+
}
325+
++it;
318326
}
319327
}
320328
}

0 commit comments

Comments
 (0)