@@ -714,53 +714,36 @@ int middle_pgsql_t::ways_delete(osmid_t osm_id)
714714 return 0 ;
715715}
716716
717- void middle_pgsql_t::iterate_ways (middle_t ::cb_func &callback )
717+ void middle_pgsql_t::iterate_ways (middle_t ::pending_processor& pf )
718718{
719- // The flag we pass to indicate that the way in question might exist already in the database */
720- int exists = Append;
721719 time_t start, end;
722720 time (&start);
721+
723722 fprintf (stderr, " \n Going over pending ways...\n " );
724723
725724 // Make sure we're out of copy mode */
726725 pgsql_endCopy ( way_table );
727726
728727 if (out_options->flat_node_cache_enabled ) persistent_cache.reset ();
729728
730- size_t pending_count = ways_pending_tracker->size ();
731- fprintf (stderr, " \t %zu ways are pending\n " , pending_count);
732-
733- /* *
734- * TODO
735- * To speed up processing of pending ways, fork noProcs worker processes
736- * each of which independently goes through an equal subset of the pending ways array
737- */
738- fprintf (stderr, " \n Using %i helper-processes\n " , 1 );
739-
740729 if (out_options->flat_node_cache_enabled ) persistent_cache.reset (new node_persistent_cache (out_options,1 ,cache)); /* at this point we always want to be in append mode, to not delete and recreate the node cache file */
741730
742- // some spaces at end, so that processings outputs get cleaned if already existing */
743- fprintf (stderr, " \r Helper process %i out of %i initialised \n " , 0 , 1 );
744-
745- // in memory processing pending ways
731+ // enqueue the jobs
746732 osmid_t id;
747- int count = 0 ;
748- while ((id = ways_pending_tracker->pop_mark ()) != std::numeric_limits<osmid_t >::max ())
733+ while (id_tracker::is_valid (id = ways_pending_tracker->pop_mark ()))
749734 {
750- // progress update
751- if (count++ %1000 == 0 )
752- {
753- time (&end);
754- fprintf (stderr, " \r processing way (%dk) at %.2fk/s" , count/1000 ,
755- end > start ? ((double )count / 1000.0 / (double )(end - start)) : 0 );
756- }
757-
758- // send it to the backends, mark it done and cleanup
759- callback (id, exists);
735+ pf.enqueue (id);
760736 }
761737
738+ size_t pending_count = pf.size ();
739+ fprintf (stderr, " \t %zu ways are pending\n " , pending_count);
740+ fprintf (stderr, " \n Using %i helper-processes\n " , pf.thread_count ());
741+
742+ // let the threads work on them
743+ pf.process_ways ();
744+
762745 time (&end);
763- fprintf (stderr, " \r Process %i finished processing %i ways in %i sec\n " , 0 , count , (int )(end - start));
746+ fprintf (stderr, " \r Process %i finished processing %i ways in %i sec\n " , 0 , pending_count , (int )(end - start));
764747
765748 fprintf (stderr, " \n All child processes exited\n " );
766749
@@ -1530,3 +1513,7 @@ boost::shared_ptr<const middle_query_t> middle_pgsql_t::get_instance() const {
15301513
15311514 return boost::shared_ptr<middle_query_t >(mid);
15321515}
1516+
1517+ size_t middle_pgsql_t::pending_count () const {
1518+ return ways_pending_tracker->size () + rels_pending_tracker->size ();
1519+ }
0 commit comments