Skip to content

Commit e733b90

Browse files
committed
Iterate over outputs in threads making queue simpler and shorter
1 parent d4e2e64 commit e733b90

File tree

1 file changed

+14
-32
lines changed

1 file changed

+14
-32
lines changed

src/osmdata.cpp

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -163,27 +163,17 @@ void osmdata_t::flush() const
163163

164164
namespace {
165165

166-
struct pending_job_t
167-
{
168-
osmid_t osm_id;
169-
size_t output_id;
170-
171-
pending_job_t() : osm_id(0), output_id(0) {}
172-
pending_job_t(osmid_t id, size_t oid) : osm_id(id), output_id(oid) {}
173-
};
174-
175-
using pending_queue_t = std::stack<pending_job_t>;
176-
177166
struct pending_threaded_processor : public pending_processor
178167
{
179168
using output_vec_t = std::vector<std::shared_ptr<output_t>>;
169+
using pending_queue_t = std::stack<osmid_t>;
180170

181171
static void do_jobs(output_vec_t const &outputs, pending_queue_t &queue,
182172
std::mutex &mutex, bool ways)
183173
{
184174
while (true) {
185175
//get the job off the queue synchronously
186-
pending_job_t job;
176+
osmid_t job;
187177
mutex.lock();
188178
if (queue.empty()) {
189179
mutex.unlock();
@@ -195,9 +185,13 @@ struct pending_threaded_processor : public pending_processor
195185

196186
//process it
197187
if (ways) {
198-
outputs.at(job.output_id)->pending_way(job.osm_id);
188+
for (auto const &out : outputs) {
189+
out->pending_way(job);
190+
}
199191
} else {
200-
outputs.at(job.output_id)->pending_relation(job.osm_id);
192+
for (auto const &out : outputs) {
193+
out->pending_relation(job);
194+
}
201195
}
202196
}
203197
}
@@ -233,19 +227,16 @@ struct pending_threaded_processor : public pending_processor
233227
outs[0]->get_options()->database_options.conninfo());
234228

235229
for (auto const &out : outs) {
236-
m_clones[i].push_back(out->clone(midq, copy_thread));
230+
if (out->need_forward_dependencies()) {
231+
m_clones[i].push_back(out->clone(midq, copy_thread));
232+
}
237233
}
238234
}
239235
}
240236

241-
void enqueue_way(osmid_t id) override
242-
{
243-
for (size_t i = 0; i < outs.size(); ++i) {
244-
if (outs[i]->need_forward_dependencies()) {
245-
queue.emplace(id, i);
246-
}
247-
}
248-
}
237+
void enqueue_way(osmid_t id) override { queue.emplace(id); }
238+
239+
void enqueue_relation(osmid_t id) override { queue.emplace(id); }
249240

250241
//waits for the completion of all outstanding jobs
251242
void process_ways() override
@@ -297,15 +288,6 @@ struct pending_threaded_processor : public pending_processor
297288
}
298289
}
299290

300-
void enqueue_relation(osmid_t id) override
301-
{
302-
for (size_t i = 0; i < outs.size(); ++i) {
303-
if (outs[i]->need_forward_dependencies()) {
304-
queue.emplace(id, i);
305-
}
306-
}
307-
}
308-
309291
void process_relations() override
310292
{
311293
auto const ids_queued = queue.size();

0 commit comments

Comments
 (0)