[generator] Review fixes.

This commit is contained in:
Maksim Andrianov 2019-08-14 18:29:50 +03:00 committed by mpimenov
parent f6a1a51d0f
commit d9b3779963
4 changed files with 19 additions and 18 deletions

View file

@ -23,6 +23,6 @@ struct ProcessedData
std::vector<std::string> m_affiliations;
};
using FeatureProcessorChank = base::threads::DataWrapper<std::vector<ProcessedData>>;
using FeatureProcessorQueue = base::threads::ThreadSafeQueue<FeatureProcessorChank>;
using FeatureProcessorChunk = base::threads::DataWrapper<std::vector<ProcessedData>>;
using FeatureProcessorQueue = base::threads::ThreadSafeQueue<FeatureProcessorChunk>;
} // namespace generator

View file

@ -159,16 +159,16 @@ bool RawGenerator::GenerateFilteredFeatures()
SourceReader reader = m_genInfo.m_osmFileName.empty() ? SourceReader()
: SourceReader(m_genInfo.m_osmFileName);
std::unique_ptr<ProcessorOsmElementsInterface> sourseProcessor;
std::unique_ptr<ProcessorOsmElementsInterface> sourceProcessor;
switch (m_genInfo.m_osmFileType) {
case feature::GenerateInfo::OsmSourceType::O5M:
sourseProcessor = std::make_unique<ProcessorOsmElementsFromO5M>(reader);
sourceProcessor = std::make_unique<ProcessorOsmElementsFromO5M>(reader);
break;
case feature::GenerateInfo::OsmSourceType::XML:
sourseProcessor = std::make_unique<ProcessorXmlElementsFromXml>(reader);
sourceProcessor = std::make_unique<ProcessorXmlElementsFromXml>(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<OsmElement> elements(m_chunkSize);
while(sourseProcessor->TryRead(elements[element_pos]))
while (sourceProcessor->TryRead(elements[element_pos]))
{
if (++element_pos != m_chunkSize)
continue;

View file

@ -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<std::string> RawGeneratorWriter::GetNames()
return names;
}
void RawGeneratorWriter::Write(std::vector<ProcessedData> const & vecChanks)
void RawGeneratorWriter::Write(std::vector<ProcessedData> 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<ProcessedData> const & vecChanks)
}
auto & writer = writerIt->second;
auto const & buffer = chank.m_buffer;
auto const & buffer = chunk.m_buffer;
WriteVarUint(*writer, static_cast<uint32_t>(buffer.size()));
writer->Write(buffer.data(), buffer.size());
}

View file

@ -13,14 +13,14 @@ TranslatorsPool::TranslatorsPool(std::shared_ptr<TranslatorInterface> 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<OsmElement> && elements)
{
std::shared_ptr<TranslatorInterface> 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<TranslatorPtr> left;