Don't wrap StaticRTree in thread-specfic ptr

This commit is contained in:
Patrick Niklaus
2016-05-07 01:53:11 +02:00
parent 2acde49f0f
commit f5aa5c0769
2 changed files with 47 additions and 132 deletions
@@ -83,8 +83,8 @@ class InternalDataFacade final : public BaseDataFacade
util::ShM<std::string, false>::vector m_datasource_names; util::ShM<std::string, false>::vector m_datasource_names;
extractor::ProfileProperties m_profile_properties; extractor::ProfileProperties m_profile_properties;
boost::thread_specific_ptr<InternalRTree> m_static_rtree; std::unique_ptr<InternalRTree> m_static_rtree;
boost::thread_specific_ptr<InternalGeospatialQuery> m_geospatial_query; std::unique_ptr<InternalGeospatialQuery> m_geospatial_query;
boost::filesystem::path ram_index_path; boost::filesystem::path ram_index_path;
boost::filesystem::path file_index_path; boost::filesystem::path file_index_path;
util::RangeTable<16, false> m_name_table; util::RangeTable<16, false> m_name_table;
@@ -313,6 +313,9 @@ class InternalDataFacade final : public BaseDataFacade
util::SimpleLogger().Write() << "loading street names"; util::SimpleLogger().Write() << "loading street names";
LoadStreetNames(config.names_data_path); LoadStreetNames(config.names_data_path);
util::SimpleLogger().Write() << "loading rtree";
LoadRTree();
} }
// search graph access // search graph access
@@ -378,11 +381,7 @@ class InternalDataFacade final : public BaseDataFacade
std::vector<RTreeLeaf> GetEdgesInBox(const util::Coordinate south_west, std::vector<RTreeLeaf> GetEdgesInBox(const util::Coordinate south_west,
const util::Coordinate north_east) override final const util::Coordinate north_east) override final
{ {
if (!m_static_rtree.get())
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
const util::RectangleInt2D bbox{south_west.lon, north_east.lon, south_west.lat, const util::RectangleInt2D bbox{south_west.lon, north_east.lon, south_west.lat,
north_east.lat}; north_east.lat};
return m_geospatial_query->Search(bbox); return m_geospatial_query->Search(bbox);
@@ -392,11 +391,7 @@ class InternalDataFacade final : public BaseDataFacade
NearestPhantomNodesInRange(const util::Coordinate input_coordinate, NearestPhantomNodesInRange(const util::Coordinate input_coordinate,
const float max_distance) override final const float max_distance) override final
{ {
if (!m_static_rtree.get())
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodesInRange(input_coordinate, max_distance); return m_geospatial_query->NearestPhantomNodesInRange(input_coordinate, max_distance);
} }
@@ -407,11 +402,7 @@ class InternalDataFacade final : public BaseDataFacade
const int bearing, const int bearing,
const int bearing_range) override final const int bearing_range) override final
{ {
if (!m_static_rtree.get())
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodesInRange(input_coordinate, max_distance, return m_geospatial_query->NearestPhantomNodesInRange(input_coordinate, max_distance,
bearing, bearing_range); bearing, bearing_range);
@@ -421,11 +412,7 @@ class InternalDataFacade final : public BaseDataFacade
NearestPhantomNodes(const util::Coordinate input_coordinate, NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results) override final const unsigned max_results) override final
{ {
if (!m_static_rtree.get())
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results); return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results);
} }
@@ -435,11 +422,7 @@ class InternalDataFacade final : public BaseDataFacade
const unsigned max_results, const unsigned max_results,
const double max_distance) override final const double max_distance) override final
{ {
if (!m_static_rtree.get())
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results, max_distance); return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results, max_distance);
} }
@@ -450,11 +433,7 @@ class InternalDataFacade final : public BaseDataFacade
const int bearing, const int bearing,
const int bearing_range) override final const int bearing_range) override final
{ {
if (!m_static_rtree.get())
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results, bearing, return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results, bearing,
bearing_range); bearing_range);
@@ -467,11 +446,7 @@ class InternalDataFacade final : public BaseDataFacade
const int bearing, const int bearing,
const int bearing_range) override final const int bearing_range) override final
{ {
if (!m_static_rtree.get())
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results, max_distance, return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results, max_distance,
bearing, bearing_range); bearing, bearing_range);
@@ -481,11 +456,7 @@ class InternalDataFacade final : public BaseDataFacade
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate, NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const double max_distance) override final const double max_distance) override final
{ {
if (!m_static_rtree.get())
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent( return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
input_coordinate, max_distance); input_coordinate, max_distance);
@@ -494,11 +465,7 @@ class InternalDataFacade final : public BaseDataFacade
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::Coordinate input_coordinate) override final const util::Coordinate input_coordinate) override final
{ {
if (!m_static_rtree.get())
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent( return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
input_coordinate); input_coordinate);
@@ -510,11 +477,7 @@ class InternalDataFacade final : public BaseDataFacade
const int bearing, const int bearing,
const int bearing_range) override final const int bearing_range) override final
{ {
if (!m_static_rtree.get())
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent( return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
input_coordinate, max_distance, bearing, bearing_range); input_coordinate, max_distance, bearing, bearing_range);
@@ -525,11 +488,7 @@ class InternalDataFacade final : public BaseDataFacade
const int bearing, const int bearing,
const int bearing_range) override final const int bearing_range) override final
{ {
if (!m_static_rtree.get())
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent( return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
input_coordinate, bearing, bearing_range); input_coordinate, bearing, bearing_range);
+16 -60
View File
@@ -55,7 +55,6 @@ class SharedDataFacade final : public BaseDataFacade
using SharedRTree = using SharedRTree =
util::StaticRTree<RTreeLeaf, util::ShM<util::Coordinate, true>::vector, true>; util::StaticRTree<RTreeLeaf, util::ShM<util::Coordinate, true>::vector, true>;
using SharedGeospatialQuery = GeospatialQuery<SharedRTree, BaseDataFacade>; using SharedGeospatialQuery = GeospatialQuery<SharedRTree, BaseDataFacade>;
using TimeStampedRTreePair = std::pair<unsigned, std::shared_ptr<SharedRTree>>;
using RTreeNode = SharedRTree::TreeNode; using RTreeNode = SharedRTree::TreeNode;
storage::SharedDataLayout *data_layout; storage::SharedDataLayout *data_layout;
@@ -71,7 +70,7 @@ class SharedDataFacade final : public BaseDataFacade
std::unique_ptr<storage::SharedMemory> m_layout_memory; std::unique_ptr<storage::SharedMemory> m_layout_memory;
std::unique_ptr<storage::SharedMemory> m_large_memory; std::unique_ptr<storage::SharedMemory> m_large_memory;
std::string m_timestamp; std::string m_timestamp;
extractor::ProfileProperties* m_profile_properties; extractor::ProfileProperties *m_profile_properties;
std::shared_ptr<util::ShM<util::Coordinate, true>::vector> m_coordinate_list; std::shared_ptr<util::ShM<util::Coordinate, true>::vector> m_coordinate_list;
util::ShM<NodeID, true>::vector m_via_node_list; util::ShM<NodeID, true>::vector m_via_node_list;
@@ -89,8 +88,8 @@ class SharedDataFacade final : public BaseDataFacade
util::ShM<std::size_t, true>::vector m_datasource_name_offsets; util::ShM<std::size_t, true>::vector m_datasource_name_offsets;
util::ShM<std::size_t, true>::vector m_datasource_name_lengths; util::ShM<std::size_t, true>::vector m_datasource_name_lengths;
boost::thread_specific_ptr<std::pair<unsigned, std::shared_ptr<SharedRTree>>> m_static_rtree; std::unique_ptr<SharedRTree> m_static_rtree;
boost::thread_specific_ptr<SharedGeospatialQuery> m_geospatial_query; std::unique_ptr<SharedGeospatialQuery> m_geospatial_query;
boost::filesystem::path file_index_path; boost::filesystem::path file_index_path;
std::shared_ptr<util::RangeTable<16, true>> m_name_table; std::shared_ptr<util::RangeTable<16, true>> m_name_table;
@@ -104,8 +103,8 @@ class SharedDataFacade final : public BaseDataFacade
void LoadProfileProperties() void LoadProfileProperties()
{ {
m_profile_properties = m_profile_properties = data_layout->GetBlockPtr<extractor::ProfileProperties>(
data_layout->GetBlockPtr<extractor::ProfileProperties>(shared_memory, storage::SharedDataLayout::PROPERTIES); shared_memory, storage::SharedDataLayout::PROPERTIES);
} }
void LoadTimestamp() void LoadTimestamp()
@@ -124,13 +123,11 @@ class SharedDataFacade final : public BaseDataFacade
auto tree_ptr = data_layout->GetBlockPtr<RTreeNode>( auto tree_ptr = data_layout->GetBlockPtr<RTreeNode>(
shared_memory, storage::SharedDataLayout::R_SEARCH_TREE); shared_memory, storage::SharedDataLayout::R_SEARCH_TREE);
m_static_rtree.reset(new TimeStampedRTreePair( m_static_rtree.reset(new SharedRTree(
CURRENT_TIMESTAMP,
util::make_unique<SharedRTree>(
tree_ptr, data_layout->num_entries[storage::SharedDataLayout::R_SEARCH_TREE], tree_ptr, data_layout->num_entries[storage::SharedDataLayout::R_SEARCH_TREE],
file_index_path, m_coordinate_list))); file_index_path, m_coordinate_list));
m_geospatial_query.reset( m_geospatial_query.reset(
new SharedGeospatialQuery(*m_static_rtree->second, m_coordinate_list, *this)); new SharedGeospatialQuery(*m_static_rtree, m_coordinate_list, *this));
} }
void LoadGraph() void LoadGraph()
@@ -165,8 +162,7 @@ class SharedDataFacade final : public BaseDataFacade
auto turn_instruction_list_ptr = auto turn_instruction_list_ptr =
data_layout->GetBlockPtr<extractor::guidance::TurnInstruction>( data_layout->GetBlockPtr<extractor::guidance::TurnInstruction>(
shared_memory, storage::SharedDataLayout::TURN_INSTRUCTION); shared_memory, storage::SharedDataLayout::TURN_INSTRUCTION);
util::ShM<extractor::guidance::TurnInstruction, true>::vector util::ShM<extractor::guidance::TurnInstruction, true>::vector turn_instruction_list(
turn_instruction_list(
turn_instruction_list_ptr, turn_instruction_list_ptr,
data_layout->num_entries[storage::SharedDataLayout::TURN_INSTRUCTION]); data_layout->num_entries[storage::SharedDataLayout::TURN_INSTRUCTION]);
m_turn_instruction_list = std::move(turn_instruction_list); m_turn_instruction_list = std::move(turn_instruction_list);
@@ -234,8 +230,8 @@ class SharedDataFacade final : public BaseDataFacade
auto geometries_list_ptr = auto geometries_list_ptr =
data_layout->GetBlockPtr<extractor::CompressedEdgeContainer::CompressedEdge>( data_layout->GetBlockPtr<extractor::CompressedEdgeContainer::CompressedEdge>(
shared_memory, storage::SharedDataLayout::GEOMETRIES_LIST); shared_memory, storage::SharedDataLayout::GEOMETRIES_LIST);
util::ShM<extractor::CompressedEdgeContainer::CompressedEdge, true>::vector util::ShM<extractor::CompressedEdgeContainer::CompressedEdge, true>::vector geometry_list(
geometry_list(geometries_list_ptr, geometries_list_ptr,
data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_LIST]); data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_LIST]);
m_geometry_list = std::move(geometry_list); m_geometry_list = std::move(geometry_list);
@@ -354,6 +350,7 @@ class SharedDataFacade final : public BaseDataFacade
LoadNames(); LoadNames();
LoadCoreInformation(); LoadCoreInformation();
LoadProfileProperties(); LoadProfileProperties();
LoadRTree();
util::SimpleLogger().Write() << "number of geometries: " util::SimpleLogger().Write() << "number of geometries: "
<< m_coordinate_list->size(); << m_coordinate_list->size();
@@ -468,11 +465,7 @@ class SharedDataFacade final : public BaseDataFacade
std::vector<RTreeLeaf> GetEdgesInBox(const util::Coordinate south_west, std::vector<RTreeLeaf> GetEdgesInBox(const util::Coordinate south_west,
const util::Coordinate north_east) override final const util::Coordinate north_east) override final
{ {
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
const util::RectangleInt2D bbox{south_west.lon, north_east.lon, south_west.lat, const util::RectangleInt2D bbox{south_west.lon, north_east.lon, south_west.lat,
north_east.lat}; north_east.lat};
return m_geospatial_query->Search(bbox); return m_geospatial_query->Search(bbox);
@@ -482,11 +475,7 @@ class SharedDataFacade final : public BaseDataFacade
NearestPhantomNodesInRange(const util::Coordinate input_coordinate, NearestPhantomNodesInRange(const util::Coordinate input_coordinate,
const float max_distance) override final const float max_distance) override final
{ {
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodesInRange(input_coordinate, max_distance); return m_geospatial_query->NearestPhantomNodesInRange(input_coordinate, max_distance);
} }
@@ -497,11 +486,7 @@ class SharedDataFacade final : public BaseDataFacade
const int bearing, const int bearing,
const int bearing_range) override final const int bearing_range) override final
{ {
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodesInRange(input_coordinate, max_distance, return m_geospatial_query->NearestPhantomNodesInRange(input_coordinate, max_distance,
bearing, bearing_range); bearing, bearing_range);
@@ -511,11 +496,7 @@ class SharedDataFacade final : public BaseDataFacade
NearestPhantomNodes(const util::Coordinate input_coordinate, NearestPhantomNodes(const util::Coordinate input_coordinate,
const unsigned max_results) override final const unsigned max_results) override final
{ {
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results); return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results);
} }
@@ -525,11 +506,7 @@ class SharedDataFacade final : public BaseDataFacade
const unsigned max_results, const unsigned max_results,
const double max_distance) override final const double max_distance) override final
{ {
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results, max_distance); return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results, max_distance);
} }
@@ -540,11 +517,7 @@ class SharedDataFacade final : public BaseDataFacade
const int bearing, const int bearing,
const int bearing_range) override final const int bearing_range) override final
{ {
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results, bearing, return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results, bearing,
bearing_range); bearing_range);
@@ -557,11 +530,7 @@ class SharedDataFacade final : public BaseDataFacade
const int bearing, const int bearing,
const int bearing_range) override final const int bearing_range) override final
{ {
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results, max_distance, return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results, max_distance,
bearing, bearing_range); bearing, bearing_range);
@@ -570,11 +539,7 @@ class SharedDataFacade final : public BaseDataFacade
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
const util::Coordinate input_coordinate) override final const util::Coordinate input_coordinate) override final
{ {
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent( return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
input_coordinate); input_coordinate);
@@ -584,11 +549,7 @@ class SharedDataFacade final : public BaseDataFacade
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate, NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
const double max_distance) override final const double max_distance) override final
{ {
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent( return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
input_coordinate, max_distance); input_coordinate, max_distance);
@@ -600,11 +561,7 @@ class SharedDataFacade final : public BaseDataFacade
const int bearing, const int bearing,
const int bearing_range) override final const int bearing_range) override final
{ {
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent( return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
input_coordinate, max_distance, bearing, bearing_range); input_coordinate, max_distance, bearing, bearing_range);
@@ -615,11 +572,7 @@ class SharedDataFacade final : public BaseDataFacade
const int bearing, const int bearing,
const int bearing_range) override final const int bearing_range) override final
{ {
if (!m_static_rtree.get() || CURRENT_TIMESTAMP != m_static_rtree->first)
{
LoadRTree();
BOOST_ASSERT(m_geospatial_query.get()); BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent( return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
input_coordinate, bearing, bearing_range); input_coordinate, bearing, bearing_range);
@@ -710,7 +663,10 @@ class SharedDataFacade final : public BaseDataFacade
std::string GetTimestamp() const override final { return m_timestamp; } std::string GetTimestamp() const override final { return m_timestamp; }
bool GetContinueStraightDefault() const override final { return m_profile_properties->continue_straight_at_waypoint; } bool GetContinueStraightDefault() const override final
{
return m_profile_properties->continue_straight_at_waypoint;
}
}; };
} }
} }