From d9b377996389606d34824969b42cd502c41f3e26 Mon Sep 17 00:00:00 2001 From: Maksim Andrianov Date: Wed, 14 Aug 2019 18:29:50 +0300 Subject: [PATCH] [generator] Review fixes. --- generator/features_processing_helpers.hpp | 4 ++-- generator/raw_generator.cpp | 10 +++++----- generator/raw_generator_writer.cpp | 16 ++++++++-------- generator/translators_pool.cpp | 7 ++++--- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/generator/features_processing_helpers.hpp b/generator/features_processing_helpers.hpp index 9d152f4196..9fbe037e83 100644 --- a/generator/features_processing_helpers.hpp +++ b/generator/features_processing_helpers.hpp @@ -23,6 +23,6 @@ struct ProcessedData std::vector m_affiliations; }; -using FeatureProcessorChank = base::threads::DataWrapper>; -using FeatureProcessorQueue = base::threads::ThreadSafeQueue; +using FeatureProcessorChunk = base::threads::DataWrapper>; +using FeatureProcessorQueue = base::threads::ThreadSafeQueue; } // namespace generator diff --git a/generator/raw_generator.cpp b/generator/raw_generator.cpp index a7cac75cfe..2d909566e1 100644 --- a/generator/raw_generator.cpp +++ b/generator/raw_generator.cpp @@ -159,16 +159,16 @@ bool RawGenerator::GenerateFilteredFeatures() SourceReader reader = m_genInfo.m_osmFileName.empty() ? SourceReader() : SourceReader(m_genInfo.m_osmFileName); - std::unique_ptr sourseProcessor; + std::unique_ptr sourceProcessor; switch (m_genInfo.m_osmFileType) { case feature::GenerateInfo::OsmSourceType::O5M: - sourseProcessor = std::make_unique(reader); + sourceProcessor = std::make_unique(reader); break; case feature::GenerateInfo::OsmSourceType::XML: - sourseProcessor = std::make_unique(reader); + sourceProcessor = std::make_unique(reader); break; } - CHECK(sourseProcessor, ()); + CHECK(sourceProcessor, ()); TranslatorsPool translators(m_translators, m_cache, m_threadsCount); RawGeneratorWriter rawGeneratorWriter(m_queue, m_genInfo.m_tmpDir); @@ -176,7 +176,7 @@ bool RawGenerator::GenerateFilteredFeatures() size_t element_pos = 0; std::vector elements(m_chunkSize); - while(sourseProcessor->TryRead(elements[element_pos])) + while (sourceProcessor->TryRead(elements[element_pos])) { if (++element_pos != m_chunkSize) continue; diff --git a/generator/raw_generator_writer.cpp b/generator/raw_generator_writer.cpp index 0e380b00d0..4f7a115aff 100644 --- a/generator/raw_generator_writer.cpp +++ b/generator/raw_generator_writer.cpp @@ -23,14 +23,14 @@ void RawGeneratorWriter::Run() m_thread = std::thread([&]() { while (true) { - FeatureProcessorChank chank; - m_queue->WaitAndPop(chank); + FeatureProcessorChunk chunk; + m_queue->WaitAndPop(chunk); // As a sign of the end of tasks, we use an empty message. We have the right to do that, // because there is only one reader. - if (chank.IsEmpty()) + if (chunk.IsEmpty()) return; - Write(chank.Get()); + Write(chunk.Get()); } }); } @@ -47,11 +47,11 @@ std::vector RawGeneratorWriter::GetNames() return names; } -void RawGeneratorWriter::Write(std::vector const & vecChanks) +void RawGeneratorWriter::Write(std::vector const & vecChunks) { - for (auto const & chank : vecChanks) + for (auto const & chunk : vecChunks) { - for (auto const & affiliation : chank.m_affiliations) + for (auto const & affiliation : chunk.m_affiliations) { if (affiliation.empty()) continue; @@ -65,7 +65,7 @@ void RawGeneratorWriter::Write(std::vector const & vecChanks) } auto & writer = writerIt->second; - auto const & buffer = chank.m_buffer; + auto const & buffer = chunk.m_buffer; WriteVarUint(*writer, static_cast(buffer.size())); writer->Write(buffer.data(), buffer.size()); } diff --git a/generator/translators_pool.cpp b/generator/translators_pool.cpp index c132ee05c8..a4b6dc6ebd 100644 --- a/generator/translators_pool.cpp +++ b/generator/translators_pool.cpp @@ -13,14 +13,14 @@ TranslatorsPool::TranslatorsPool(std::shared_ptr const & or for (size_t i = 0; i < threadCount; ++i) m_translators.Push(original->Clone()); - CHECK_EQUAL(m_translators.size(), threadCount + 1, ()); + CHECK_EQUAL(m_translators.Size(), threadCount + 1, ()); } void TranslatorsPool::Emit(std::vector && elements) { std::shared_ptr translator; m_translators.WaitAndPop(translator); - m_threadPool.SubmitWork([&, translator, elements{move(elements)}]() mutable { + m_threadPool.SubmitWork([&, translator, elements{std::move(elements)}]() mutable { for (auto & element : elements) translator->Emit(element); @@ -42,7 +42,8 @@ bool TranslatorsPool::Finish() queue.Push(p.get_future()); } - base::thread_pool::computational::ThreadPool pool(queue.size() / 2 + 1); + base::thread_pool::computational::ThreadPool pool(queue.Size() / 2 + 1); + CHECK_GREATER_OR_EQUAL(queue.Size(), 1, ()); while (queue.Size() != 1) { std::future left;