diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt index 4abc679..4dbc61f 100644 --- a/generator/CMakeLists.txt +++ b/generator/CMakeLists.txt @@ -152,7 +152,7 @@ set( world_map_generator.hpp ) -find_package(Boost REQUIRED COMPONENTS iostreams) +find_package(Boost REQUIRED COMPONENTS iostreams filesystem) geocore_add_library(${PROJECT_NAME} ${SRC}) geocore_link_libraries(${PROJECT_NAME} diff --git a/generator/intermediate_data.cpp b/generator/intermediate_data.cpp index d06d867..8dc3557 100644 --- a/generator/intermediate_data.cpp +++ b/generator/intermediate_data.cpp @@ -3,10 +3,10 @@ #include "platform/platform.hpp" #include -#include #include #include #include +#include #include #include @@ -378,6 +378,7 @@ OSMElementCacheReader::OSMElementCacheReader(string const & name) if (!m_fileMap.is_open()) MYTHROW(Writer::OpenException, ("Failed to open", name)); + // Try aggressively (MADV_WILLNEED) and asynchronously read ahead. auto readaheadTask = std::thread([data = m_fileMap.data(), size = m_fileMap.size()] { ::madvise(const_cast(data), size, MADV_WILLNEED); }); @@ -514,10 +515,5 @@ shared_ptr const & IntermediateData::GetCache() const { return m_reader; } - -shared_ptr IntermediateData::Clone() const -{ - return shared_from_this(); -} } // namespace cache } // namespace generator diff --git a/generator/intermediate_data.hpp b/generator/intermediate_data.hpp index 78e40e0..455446d 100644 --- a/generator/intermediate_data.hpp +++ b/generator/intermediate_data.hpp @@ -366,12 +366,11 @@ CreatePointStorageReader(feature::GenerateInfo::NodeStorageType type, std::strin std::unique_ptr CreatePointStorageWriter(feature::GenerateInfo::NodeStorageType type, std::string const & name); -class IntermediateData : public std::enable_shared_from_this +class IntermediateData { public: explicit IntermediateData(feature::GenerateInfo const & info); std::shared_ptr const & GetCache() const; - std::shared_ptr Clone() const; private: feature::GenerateInfo const & m_info; diff --git a/generator/osm_source.cpp b/generator/osm_source.cpp index 8737e74..682dd8f 100644 --- a/generator/osm_source.cpp +++ b/generator/osm_source.cpp @@ -15,7 +15,6 @@ #include "base/file_name_utils.hpp" #include -#include #include #include #include @@ -254,11 +253,11 @@ void BuildIntermediateDataFromO5M( auto sourceMap = boost::iostreams::mapped_file_source{filename}; if (!sourceMap.is_open()) MYTHROW(Writer::OpenException, ("Failed to open", filename)); - // Try aggressively (MADV_WILLNEED) and asynchronously (std::launch::async) read ahead - // the o5m-file. - std::async(std::launch::async, [data = sourceMap.data(), size = sourceMap.size()] { + // Try aggressively (MADV_WILLNEED) and asynchronously read ahead the o5m-file. + auto readaheadTask = std::thread([data = sourceMap.data(), size = sourceMap.size()] { ::madvise(const_cast(data), size, MADV_WILLNEED); }); + readaheadTask.detach(); constexpr size_t chunkSize = 10'000; std::vector threads; diff --git a/generator/raw_generator.cpp b/generator/raw_generator.cpp index 82d224c..a862fe1 100644 --- a/generator/raw_generator.cpp +++ b/generator/raw_generator.cpp @@ -223,11 +223,11 @@ boost::iostreams::mapped_file_source RawGenerator::MakeFileMap(std::string const if (!fileMap.is_open()) MYTHROW(Writer::OpenException, ("Failed to open", filename)); - // Try aggressively (MADV_WILLNEED) and asynchronously (std::launch::async) read ahead - // the o5m-file. - std::async(std::launch::async, [data = fileMap.data(), size = fileMap.size()] { + // Try aggressively (MADV_WILLNEED) and asynchronously read ahead the o5m-file. + auto readaheadTask = std::thread([data = fileMap.data(), size = fileMap.size()] { ::madvise(const_cast(data), size, MADV_WILLNEED); }); + readaheadTask.detach(); return fileMap; } diff --git a/generator/translator.hpp b/generator/translator.hpp index 05c4541..bae1f25 100644 --- a/generator/translator.hpp +++ b/generator/translator.hpp @@ -47,7 +47,7 @@ protected: template decltype(auto) CloneBase() const { - auto cache = m_cache->Clone(); + auto cache = m_cache; auto processor = m_processor->Clone(); auto featureMaker = m_featureMaker->Clone(); auto filter = m_filter->Clone();