2828
2929osmdata_t ::osmdata_t (std::unique_ptr<dependency_manager_t > dependency_manager,
3030 std::shared_ptr<middle_t > mid,
31- std::vector<std::shared_ptr<output_t >> outs,
32- options_t const &options)
31+ std::shared_ptr<output_t > output, options_t const &options)
3332: m_dependency_manager(std::move(dependency_manager)), m_mid(std::move(mid)),
34- m_outs (std::move(outs )), m_conninfo(options.database_options.conninfo()),
33+ m_output (std::move(output )), m_conninfo(options.database_options.conninfo()),
3534 m_bbox(options.bbox), m_num_procs(options.num_procs),
3635 m_append(options.append), m_droptemp(options.droptemp),
3736 m_parallel_indexing(options.parallel_indexing),
@@ -40,7 +39,7 @@ osmdata_t::osmdata_t(std::unique_ptr<dependency_manager_t> dependency_manager,
4039{
4140 assert (m_dependency_manager);
4241 assert (m_mid);
43- assert (!m_outs. empty () );
42+ assert (m_output );
4443}
4544
4645void osmdata_t::node (osmium::Node const &node)
@@ -91,9 +90,7 @@ void osmdata_t::after_ways() { m_mid->after_ways(); }
9190void osmdata_t::relation (osmium::Relation const &rel)
9291{
9392 if (m_append && !rel.deleted ()) {
94- for (auto const &out : m_outs) {
95- out->select_relation_members (rel.id ());
96- }
93+ m_output->select_relation_members (rel.id ());
9794 }
9895
9996 m_mid->relation (rel);
@@ -117,81 +114,59 @@ void osmdata_t::after_relations() { m_mid->after_relations(); }
117114void osmdata_t::node_add (osmium::Node const &node) const
118115{
119116 if (m_with_extra_attrs || !node.tags ().empty ()) {
120- for (auto const &out : m_outs) {
121- out->node_add (node);
122- }
117+ m_output->node_add (node);
123118 }
124119}
125120
126121void osmdata_t::way_add (osmium::Way *way) const
127122{
128123 if (m_with_extra_attrs || !way->tags ().empty ()) {
129- for (auto const &out : m_outs) {
130- out->way_add (way);
131- }
124+ m_output->way_add (way);
132125 }
133126}
134127
135128void osmdata_t::relation_add (osmium::Relation const &rel) const
136129{
137130 if (m_with_extra_attrs || !rel.tags ().empty ()) {
138- for (auto const &out : m_outs) {
139- out->relation_add (rel);
140- }
131+ m_output->relation_add (rel);
141132 }
142133}
143134
144135void osmdata_t::node_modify (osmium::Node const &node) const
145136{
146- for (auto const &out : m_outs) {
147- out->node_modify (node);
148- }
149-
137+ m_output->node_modify (node);
150138 m_dependency_manager->node_changed (node.id ());
151139}
152140
153141void osmdata_t::way_modify (osmium::Way *way) const
154142{
155- for (auto const &out : m_outs) {
156- out->way_modify (way);
157- }
158-
143+ m_output->way_modify (way);
159144 m_dependency_manager->way_changed (way->id ());
160145}
161146
162147void osmdata_t::relation_modify (osmium::Relation const &rel) const
163148{
164- for (auto const &out : m_outs) {
165- out->relation_modify (rel);
166- }
149+ m_output->relation_modify (rel);
167150}
168151
169152void osmdata_t::node_delete (osmid_t id) const
170153{
171- for (auto const &out : m_outs) {
172- out->node_delete (id);
173- }
154+ m_output->node_delete (id);
174155}
175156
176157void osmdata_t::way_delete (osmid_t id) const
177158{
178- for (auto const &out : m_outs) {
179- out->way_delete (id);
180- }
159+ m_output->way_delete (id);
181160}
182161
183162void osmdata_t::relation_delete (osmid_t id) const
184163{
185- for (auto const &out : m_outs) {
186- out->relation_delete (id);
187- }
164+ m_output->relation_delete (id);
188165}
189166
190167void osmdata_t::start () const
191168{
192- for (auto const &out : m_outs) {
193- out->start ();
194- }
169+ m_output->start ();
195170}
196171
197172namespace {
@@ -205,24 +180,20 @@ namespace {
205180class multithreaded_processor
206181{
207182public:
208- using output_vec_t = std::vector<std::shared_ptr<output_t >>;
209-
210183 multithreaded_processor (std::string const &conninfo,
211184 std::shared_ptr<middle_t > const &mid,
212- output_vec_t outs, size_t thread_count)
213- : m_outputs(std::move(outs))
185+ std::shared_ptr<output_t > output,
186+ std::size_t thread_count)
187+ : m_output(std::move(output))
214188 {
215- assert (!m_outputs.empty ());
189+ assert (mid);
190+ assert (m_output);
216191
217- // For each thread we create clones of all the outputs.
218- m_clones.resize (thread_count);
219- for (size_t i = 0 ; i < thread_count; ++i) {
192+ // For each thread we create a clone of the output.
193+ for (std::size_t i = 0 ; i < thread_count; ++i) {
220194 auto const midq = mid->get_query_instance ();
221195 auto copy_thread = std::make_shared<db_copy_thread_t >(conninfo);
222-
223- for (auto const &out : m_outputs) {
224- m_clones[i].push_back (out->clone (midq, copy_thread));
225- }
196+ m_clones.push_back (m_output->clone (midq, copy_thread));
226197 }
227198 }
228199
@@ -262,17 +233,12 @@ class multithreaded_processor
262233
263234 /* *
264235 * Collect expiry tree information from all clones and merge it back
265- * into the original outputs .
236+ * into the original output .
266237 */
267238 void merge_expire_trees ()
268239 {
269- std::size_t n = 0 ;
270- for (auto const &output : m_outputs) {
271- for (auto const &clone : m_clones) {
272- assert (n < clone.size ());
273- output->merge_expire_trees (clone[n].get ());
274- }
275- ++n;
240+ for (auto const &clone : m_clones) {
241+ m_output->merge_expire_trees (clone.get ());
276242 }
277243 }
278244
@@ -296,23 +262,15 @@ class multithreaded_processor
296262
297263 /* *
298264 * Runs in the worker threads: As long as there are any, get ids from
299- * the queue and let the outputs process it by calling "func".
265+ * the queue and let the output process it by calling "func".
300266 */
301- static void run (output_vec_t const &outputs , idlist_t *queue,
267+ static void run (std::shared_ptr< output_t > output , idlist_t *queue,
302268 std::mutex *mutex, output_member_fn_ptr func)
303269 {
304270 while (osmid_t const id = pop_id (queue, mutex)) {
305- for (auto const &output : outputs) {
306- if (output) {
307- (output.get ()->*func)(id);
308- }
309- }
310- }
311- for (auto const &output : outputs) {
312- if (output) {
313- output->sync ();
314- }
271+ (output.get ()->*func)(id);
315272 }
273+ output->sync ();
316274 }
317275
318276 // / Runs in a worker thread: Update progress display once per second.
@@ -375,11 +333,11 @@ class multithreaded_processor
375333 timer.per_second (ids_queued));
376334 }
377335
378- // / Clones of all outputs , one vector of clones per thread.
379- std::vector<output_vec_t > m_clones;
336+ // / Clones of output , one clone per thread.
337+ std::vector<std::shared_ptr< output_t > > m_clones;
380338
381- // / All outputs .
382- output_vec_t m_outputs ;
339+ // / The output .
340+ std::shared_ptr< output_t > m_output ;
383341
384342 // / Mutex to make sure worker threads coordinate access to queue.
385343 std::mutex m_mutex;
@@ -389,7 +347,7 @@ class multithreaded_processor
389347
390348void osmdata_t::process_dependents () const
391349{
392- multithreaded_processor proc{m_conninfo, m_mid, m_outs ,
350+ multithreaded_processor proc{m_conninfo, m_mid, m_output ,
393351 (std::size_t )m_num_procs};
394352
395353 // stage 1b processing: process parents of changed objects
@@ -401,10 +359,8 @@ void osmdata_t::process_dependents() const
401359 }
402360
403361 // stage 1c processing: mark parent relations of marked objects as changed
404- for (auto &out : m_outs) {
405- for (auto const id : out->get_marked_way_ids ()) {
406- m_dependency_manager->way_changed (id);
407- }
362+ for (auto const id : m_output->get_marked_way_ids ()) {
363+ m_dependency_manager->way_changed (id);
408364 }
409365
410366 // process parent relations of marked ways
@@ -414,12 +370,7 @@ void osmdata_t::process_dependents() const
414370 }
415371}
416372
417- void osmdata_t::reprocess_marked () const
418- {
419- for (auto &out : m_outs) {
420- out->reprocess_marked ();
421- }
422- }
373+ void osmdata_t::reprocess_marked () const { m_output->reprocess_marked (); }
423374
424375void osmdata_t::postprocess_database () const
425376{
@@ -436,9 +387,7 @@ void osmdata_t::postprocess_database() const
436387 m_mid->stop (pool);
437388 }
438389
439- for (auto &out : m_outs) {
440- out->stop (&pool);
441- }
390+ m_output->stop (&pool);
442391
443392 if (!m_droptemp) {
444393 // When keeping middle tables, there is quite a large index created
@@ -455,9 +404,7 @@ void osmdata_t::postprocess_database() const
455404
456405void osmdata_t::stop () const
457406{
458- for (auto &out : m_outs) {
459- out->sync ();
460- }
407+ m_output->sync ();
461408
462409 if (m_append && m_with_forward_dependencies) {
463410 process_dependents ();
0 commit comments