forked from organicmaps/organicmaps-tmp
Add tests for MultiProducerOneConsumer.
This commit is contained in:
parent
9a9808ea72
commit
7a2117bc2f
4 changed files with 48 additions and 10 deletions
45
generator/generator_tests/concurrent_tests.cpp
Normal file
45
generator/generator_tests/concurrent_tests.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include "../../testing/testing.hpp"
|
||||
|
||||
#include "../multiproducer_oneconsumer.hpp"
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class AccumulateTask : public MultiProducerOneConsumer::ITask
|
||||
{
|
||||
vector<uint64_t> & m_res;
|
||||
public:
|
||||
AccumulateTask(vector<uint64_t> & res) : m_res(res) {}
|
||||
|
||||
static uint64_t const s_upper = 1000000;
|
||||
|
||||
virtual void RunBase()
|
||||
{
|
||||
uint64_t summ = 0;
|
||||
for (uint64_t i = 0; i <= s_upper; ++i)
|
||||
summ += i;
|
||||
Emit(reinterpret_cast<void *>(summ));
|
||||
}
|
||||
|
||||
virtual void EmitBase(void * p)
|
||||
{
|
||||
m_res.push_back(reinterpret_cast<uint64_t>(p));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
UNIT_TEST(MultiProducers_Smoke)
|
||||
{
|
||||
size_t const count = 64;
|
||||
vector<uint64_t> vec;
|
||||
|
||||
MultiProducerOneConsumer runner(8);
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
runner.RunTask(new AccumulateTask(vec));
|
||||
runner.Finish();
|
||||
|
||||
TEST_EQUAL(vec.size(), count, ());
|
||||
uint64_t const res = AccumulateTask::s_upper * (AccumulateTask::s_upper + 1) / 2;
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
TEST_EQUAL(vec[i], res, ());
|
||||
}
|
|
@ -26,5 +26,5 @@ SOURCES += \
|
|||
osm_id_test.cpp \
|
||||
tesselator_test.cpp \
|
||||
triangles_tree_coding_test.cpp \
|
||||
coasts_test.cpp
|
||||
|
||||
coasts_test.cpp \
|
||||
concurrent_tests.cpp \
|
||||
|
|
|
@ -7,10 +7,7 @@
|
|||
|
||||
MultiProducerOneConsumer::MultiProducerOneConsumer(size_t tasksPerThread)
|
||||
#if PARALLEL_POLYGONIZER
|
||||
: m_tasksCount(m_ThreadPool.maxThreadCount() * tasksPerThread),
|
||||
m_ThreadPoolSemaphore(m_tasksCount)
|
||||
#else
|
||||
: m_tasksCount(1)
|
||||
: m_ThreadPoolSemaphore(m_ThreadPool.maxThreadCount() * tasksPerThread)
|
||||
#endif
|
||||
{
|
||||
#if PARALLEL_POLYGONIZER
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
|
||||
class MultiProducerOneConsumer
|
||||
{
|
||||
size_t m_tasksCount;
|
||||
|
||||
#if PARALLEL_POLYGONIZER
|
||||
QThreadPool m_ThreadPool;
|
||||
QSemaphore m_ThreadPoolSemaphore;
|
||||
|
@ -25,8 +23,6 @@ class MultiProducerOneConsumer
|
|||
public:
|
||||
MultiProducerOneConsumer(size_t tasksPerThread);
|
||||
|
||||
size_t GetTasksCount() const { return m_tasksCount; }
|
||||
|
||||
class ITask
|
||||
#if PARALLEL_POLYGONIZER
|
||||
: public QRunnable
|
||||
|
|
Loading…
Add table
Reference in a new issue