use flexible shared mem interfaces

This commit is contained in:
Dennis Luxen 2013-09-23 18:03:07 +02:00
parent 396dc21903
commit 8521b5501f
2 changed files with 36 additions and 8 deletions

View File

@ -85,8 +85,8 @@ public:
} }
StaticGraph( StaticGraph(
ShMemVector<_StrNode, UseSharedMemory> & nodes, typename ShM<_StrNode, UseSharedMemory>::vector & nodes,
ShMemVector<_StrEdge, UseSharedMemory> & edges typename ShM<_StrEdge, UseSharedMemory>::vector & edges
) { ) {
_numNodes = nodes.size(); _numNodes = nodes.size();
_numEdges = edges.size(); _numEdges = edges.size();
@ -196,8 +196,8 @@ private:
NodeIterator _numNodes; NodeIterator _numNodes;
EdgeIterator _numEdges; EdgeIterator _numEdges;
ShMemVector< _StrNode, UseSharedMemory > _nodes; typename ShM< _StrNode, UseSharedMemory >::vector _nodes;
ShMemVector< _StrEdge, UseSharedMemory > _edges; typename ShM< _StrEdge, UseSharedMemory >::vector _edges;
}; };
#endif // STATICGRAPH_H_INCLUDED #endif // STATICGRAPH_H_INCLUDED

View File

@ -21,11 +21,15 @@ or see http://www.gnu.org/licenses/agpl.txt.
#ifndef STATICRTREE_H_ #ifndef STATICRTREE_H_
#define STATICRTREE_H_ #define STATICRTREE_H_
#include "MercatorUtil.h"
#include "Coordinate.h" #include "Coordinate.h"
#include "PhantomNodes.h"
#include "DeallocatingVector.h" #include "DeallocatingVector.h"
#include "HilbertValue.h" #include "HilbertValue.h"
#include "MercatorUtil.h"
#include "PhantomNodes.h"
#include "SharedMemoryFactory.h"
#include "SharedMemoryVectorWrapper.h"
#include "../Server/DataStructures/SharedDataType.h"
#include "../Util/OSRMException.h" #include "../Util/OSRMException.h"
#include "../Util/SimpleLogger.h" #include "../Util/SimpleLogger.h"
#include "../Util/TimingUtil.h" #include "../Util/TimingUtil.h"
@ -41,6 +45,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <boost/range/algorithm_ext/erase.hpp> #include <boost/range/algorithm_ext/erase.hpp>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include <boost/type_traits.hpp>
#include <cassert> #include <cassert>
#include <cfloat> #include <cfloat>
@ -59,7 +64,7 @@ const static uint32_t RTREE_LEAF_NODE_SIZE = 1170;
static boost::thread_specific_ptr<boost::filesystem::ifstream> thread_local_rtree_stream; static boost::thread_specific_ptr<boost::filesystem::ifstream> thread_local_rtree_stream;
template<class DataT> template<class DataT, bool UseSharedMemory = false>
class StaticRTree : boost::noncopyable { class StaticRTree : boost::noncopyable {
private: private:
struct RectangleInt2D { struct RectangleInt2D {
@ -276,7 +281,7 @@ private:
} }
}; };
std::vector<TreeNode> m_search_tree; typename ShM<TreeNode, UseSharedMemory>::vector m_search_tree;
uint64_t m_element_count; uint64_t m_element_count;
const std::string m_leaf_node_filename; const std::string m_leaf_node_filename;
@ -429,7 +434,30 @@ public:
m_search_tree.resize(tree_size); m_search_tree.resize(tree_size);
tree_node_file.read((char*)&m_search_tree[0], sizeof(TreeNode)*tree_size); tree_node_file.read((char*)&m_search_tree[0], sizeof(TreeNode)*tree_size);
tree_node_file.close(); tree_node_file.close();
//open leaf node file and store thread specific pointer
if ( !boost::filesystem::exists( leaf_file ) ) {
throw OSRMException("mem index file does not exist");
}
if ( 0 == boost::filesystem::file_size( leaf_file ) ) {
throw OSRMException("mem index file is empty");
}
boost::filesystem::ifstream leaf_node_file( leaf_file, std::ios::binary );
leaf_node_file.read((char*)&m_element_count, sizeof(uint64_t));
leaf_node_file.close();
//SimpleLogger().Write() << tree_size << " nodes in search tree";
//SimpleLogger().Write() << m_element_count << " elements in leafs";
}
//Read-only operation for queries
explicit StaticRTree(
const TreeNode * tree_node_ptr,
const uint32_t number_of_nodes,
const boost::filesystem::path & leaf_file
) : m_leaf_node_filename(leaf_file.string()),
m_search_tree(tree_node_ptr, number_of_nodes)
{
//open leaf node file and store thread specific pointer //open leaf node file and store thread specific pointer
if ( !boost::filesystem::exists( leaf_file ) ) { if ( !boost::filesystem::exists( leaf_file ) ) {
throw OSRMException("mem index file does not exist"); throw OSRMException("mem index file does not exist");