Skip to content

Commit e09fccc

Browse files
committed
Disentangle the pending_processor code
1 parent 84aadc0 commit e09fccc

File tree

5 files changed

+32
-37
lines changed

5 files changed

+32
-37
lines changed

src/dependency-manager.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ bool full_dependency_manager_t::has_pending() const noexcept
4343
return !m_ways_pending_tracker.empty() || !m_rels_pending_tracker.empty();
4444
}
4545

46-
void full_dependency_manager_t::process_pending(middle_t::pending_processor &pf)
46+
void full_dependency_manager_t::process_pending(pending_processor &proc)
4747
{
4848
osmid_t id;
4949
while (id_tracker::is_valid(id = m_ways_pending_tracker.pop_mark())) {
50-
pf.enqueue_ways(id);
50+
proc.enqueue_way(id);
5151
}
5252

53-
pf.process_ways();
53+
proc.process_ways();
5454

5555
while (id_tracker::is_valid(id = m_rels_pending_tracker.pop_mark())) {
56-
pf.enqueue_relations(id);
56+
proc.enqueue_relation(id);
5757
}
5858

59-
pf.process_relations();
59+
proc.process_relations();
6060
}

src/dependency-manager.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77

88
#include <cassert>
99

10+
struct pending_processor
11+
{
12+
virtual ~pending_processor() = default;
13+
14+
virtual void enqueue_way(osmid_t id) = 0;
15+
virtual void enqueue_relation(osmid_t id) = 0;
16+
17+
virtual void process_ways() = 0;
18+
virtual void process_relations() = 0;
19+
};
20+
1021
/**
1122
* The job of the dependency manager is to keep track of the dependencies
1223
* between OSM objects, that is nodes in ways and members of relations.
@@ -64,7 +75,7 @@ class dependency_manager_t
6475
*
6576
* \post !has_pending()
6677
*/
67-
virtual void process_pending(middle_t::pending_processor &) {}
78+
virtual void process_pending(pending_processor &) {}
6879
};
6980

7081
/**
@@ -100,7 +111,7 @@ class full_dependency_manager_t : public dependency_manager_t
100111

101112
bool has_pending() const noexcept override;
102113

103-
void process_pending(middle_t::pending_processor &pf) override;
114+
void process_pending(pending_processor &proc) override;
104115

105116
/**
106117
* Get access to the pending way ids. This is for debugging only.

src/middle.hpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,6 @@ struct middle_t
127127
virtual idlist_t get_rels_by_rel(osmid_t) { return {}; }
128128
virtual idlist_t get_ways_by_rel(osmid_t) { return {}; }
129129

130-
struct pending_processor
131-
{
132-
virtual ~pending_processor() {}
133-
virtual void enqueue_ways(osmid_t id) = 0;
134-
virtual void process_ways() = 0;
135-
virtual void enqueue_relations(osmid_t id) = 0;
136-
virtual void process_relations() = 0;
137-
};
138-
139130
virtual std::shared_ptr<middle_query_t> get_query_instance() = 0;
140131
};
141132

src/osmdata.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <future>
55
#include <memory>
66
#include <mutex>
7+
#include <stack>
78
#include <stdexcept>
89
#include <utility>
910
#include <vector>
@@ -162,11 +163,18 @@ void osmdata_t::flush() const
162163

163164
namespace {
164165

165-
//TODO: have the main thread using the main middle to query the middle for batches of ways (configurable number)
166-
//and stuffing those into the work queue, so we have a single producer multi consumer threaded queue
167-
//since the fetching from middle should be faster than the processing in each backend.
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>;
168176

169-
struct pending_threaded_processor : public middle_t::pending_processor
177+
struct pending_threaded_processor : public pending_processor
170178
{
171179
using output_vec_t = std::vector<std::shared_ptr<output_t>>;
172180

@@ -241,7 +249,7 @@ struct pending_threaded_processor : public middle_t::pending_processor
241249
}
242250
}
243251

244-
void enqueue_ways(osmid_t id) override
252+
void enqueue_way(osmid_t id) override
245253
{
246254
for (size_t i = 0; i < outs.size(); ++i) {
247255
if (outs[i]->need_forward_dependencies()) {
@@ -304,7 +312,7 @@ struct pending_threaded_processor : public middle_t::pending_processor
304312
}
305313
}
306314

307-
void enqueue_relations(osmid_t id) override
315+
void enqueue_relation(osmid_t id) override
308316
{
309317
for (size_t i = 0; i < outs.size(); ++i) {
310318
if (outs[i]->need_forward_dependencies()) {

src/output.hpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,13 @@
1010
* Associated tags: name, type etc.
1111
*/
1212

13-
#include <stack>
14-
1513
#include <osmium/thread/pool.hpp>
1614

1715
#include "options.hpp"
1816

19-
struct expire_tiles;
20-
struct id_tracker;
2117
struct middle_query_t;
2218
class db_copy_thread_t;
2319

24-
struct pending_job_t
25-
{
26-
osmid_t osm_id;
27-
size_t output_id;
28-
29-
pending_job_t() : osm_id(0), output_id(0) {}
30-
pending_job_t(osmid_t id, size_t oid) : osm_id(id), output_id(oid) {}
31-
};
32-
33-
using pending_queue_t = std::stack<pending_job_t>;
34-
3520
class output_t
3621
{
3722
public:

0 commit comments

Comments
 (0)