diff --git a/base/base_tests/thread_safe_queue_tests.cpp b/base/base_tests/thread_safe_queue_tests.cpp index 1a41edb79f..d1d18c928b 100644 --- a/base/base_tests/thread_safe_queue_tests.cpp +++ b/base/base_tests/thread_safe_queue_tests.cpp @@ -5,27 +5,12 @@ #include #include +#include #include #include using namespace base::thread_pool::delayed; -UNIT_TEST(DataWrapper_DataWrapper) -{ - base::threads::DataWrapper dw1; - TEST(dw1.IsEmpty(), ()); - - base::threads::DataWrapper dw2(101); - TEST(!dw2.IsEmpty(), ()); -} - -UNIT_TEST(DataWrapper_Get) -{ - base::threads::DataWrapper dw(101); - TEST(!dw.IsEmpty(), ()); - TEST_EQUAL(dw.Get(), 101, ()); -} - UNIT_TEST(ThreadSafeQueue_ThreadSafeQueue) { base::threads::ThreadSafeQueue queue; @@ -90,22 +75,18 @@ UNIT_TEST(ThreadSafeQueue_TryPop) UNIT_TEST(ThreadSafeQueue_ExampleWithDataWrapper) { size_t const kSize = 100000; - base::threads::ThreadSafeQueue> queue; + base::threads::ThreadSafeQueue> queue; auto thread = std::thread([&]() { while (true) { - base::threads::DataWrapper dw; + std::optional dw; queue.WaitAndPop(dw); - if (dw.IsEmpty()) - { + if (!dw.has_value()) return; - } - else - { - ASSERT_GREATER_OR_EQUAL(dw.Get(), 0, ()); - ASSERT_LESS_OR_EQUAL(dw.Get(), kSize, ()); - } + + ASSERT_GREATER_OR_EQUAL(*dw, 0, ()); + ASSERT_LESS_OR_EQUAL(*dw, kSize, ()); } }); diff --git a/base/thread_safe_queue.hpp b/base/thread_safe_queue.hpp index c5fe8f5584..7198b65fbe 100644 --- a/base/thread_safe_queue.hpp +++ b/base/thread_safe_queue.hpp @@ -9,28 +9,6 @@ namespace base { namespace threads { -// DataWrapper functionality is similar to boost::optional. DataWrapper is needed to help send a -// signal to the thread, that there is no more data and it's time to finish the work, i.e. in fact, -// it will be empty only once. I don't want to use boost::optional for this, because it allocates -// memory on the heap, unlike DataWrapper, which allocates it on the stack. -template -class DataWrapper -{ -public: - DataWrapper() : m_isEmpty(true) {} - DataWrapper(T const & data) : m_data(data), m_isEmpty(false) {} - DataWrapper(T && data) : m_data(std::move(data)), m_isEmpty(false) {} - - T const & Get() const { return m_data; } - T & Get() { return m_data; } - - bool IsEmpty() const { return m_isEmpty; } - -private: - T m_data; - bool m_isEmpty; -}; - template class ThreadSafeQueue { diff --git a/generator/features_processing_helpers.hpp b/generator/features_processing_helpers.hpp index 0d70b65c12..203f6bbe23 100644 --- a/generator/features_processing_helpers.hpp +++ b/generator/features_processing_helpers.hpp @@ -5,6 +5,7 @@ #include "base/thread_safe_queue.hpp" #include +#include #include #include #include @@ -23,6 +24,6 @@ struct ProcessedData std::vector m_affiliations; }; -using FeatureProcessorChunk = base::threads::DataWrapper>; +using FeatureProcessorChunk = std::optional>; using FeatureProcessorQueue = base::threads::ThreadSafeQueue; } // namespace generator diff --git a/generator/raw_generator_writer.cpp b/generator/raw_generator_writer.cpp index c9681f616d..7e3a3890aa 100644 --- a/generator/raw_generator_writer.cpp +++ b/generator/raw_generator_writer.cpp @@ -25,10 +25,10 @@ void RawGeneratorWriter::Run() 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 (chunk.IsEmpty()) + if (!chunk.has_value()) return; - Write(chunk.Get()); + Write(*chunk); } }); }