mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 13:23:59 +00:00
Format all C++ and Java code via clang-format
Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
@@ -6,48 +6,39 @@
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
const int TASK_COUNT = 10;
|
||||
class CanceledTask : public threads::IRoutine
|
||||
{
|
||||
public:
|
||||
CanceledTask()
|
||||
{
|
||||
Cancel();
|
||||
}
|
||||
int const TASK_COUNT = 10;
|
||||
class CanceledTask : public threads::IRoutine
|
||||
{
|
||||
public:
|
||||
CanceledTask() { Cancel(); }
|
||||
|
||||
virtual void Do()
|
||||
{
|
||||
TEST_EQUAL(true, false, ());
|
||||
}
|
||||
};
|
||||
struct Condition
|
||||
{
|
||||
std::mutex m;
|
||||
std::condition_variable cv;
|
||||
};
|
||||
virtual void Do() { TEST_EQUAL(true, false, ()); }
|
||||
};
|
||||
struct Condition
|
||||
{
|
||||
std::mutex m;
|
||||
std::condition_variable cv;
|
||||
};
|
||||
|
||||
void JoinFinishFunction(threads::IRoutine * routine,
|
||||
int & finishCounter,
|
||||
Condition & cond)
|
||||
{
|
||||
cond.m.lock();
|
||||
finishCounter++;
|
||||
cond.m.unlock();
|
||||
void JoinFinishFunction(threads::IRoutine * routine, int & finishCounter, Condition & cond)
|
||||
{
|
||||
cond.m.lock();
|
||||
finishCounter++;
|
||||
cond.m.unlock();
|
||||
|
||||
delete routine;
|
||||
cond.cv.notify_one();
|
||||
}
|
||||
delete routine;
|
||||
cond.cv.notify_one();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
UNIT_TEST(ThreadPool_CanceledTaskTest)
|
||||
{
|
||||
int finishCounter = 0;
|
||||
Condition cond;
|
||||
base::ThreadPool pool(4, std::bind(&JoinFinishFunction, std::placeholders::_1,
|
||||
std::ref(finishCounter), std::ref(cond)));
|
||||
base::ThreadPool pool(4,
|
||||
std::bind(&JoinFinishFunction, std::placeholders::_1, std::ref(finishCounter), std::ref(cond)));
|
||||
|
||||
for (int i = 0; i < TASK_COUNT; ++i)
|
||||
pool.PushBack(new CanceledTask());
|
||||
@@ -57,42 +48,34 @@ UNIT_TEST(ThreadPool_CanceledTaskTest)
|
||||
TEST_EQUAL(finishCounter, TASK_COUNT, ());
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class CancelTestTask : public threads::IRoutine
|
||||
class CancelTestTask : public threads::IRoutine
|
||||
{
|
||||
public:
|
||||
explicit CancelTestTask(bool isWaitDoCall) : m_waitDoCall(isWaitDoCall), m_doCalled(false) {}
|
||||
|
||||
~CancelTestTask() { TEST_EQUAL(m_waitDoCall, m_doCalled, ()); }
|
||||
|
||||
virtual void Do()
|
||||
{
|
||||
public:
|
||||
explicit CancelTestTask(bool isWaitDoCall)
|
||||
: m_waitDoCall(isWaitDoCall)
|
||||
, m_doCalled(false)
|
||||
{
|
||||
}
|
||||
TEST_EQUAL(m_waitDoCall, true, ());
|
||||
m_doCalled = true;
|
||||
threads::Sleep(100);
|
||||
}
|
||||
|
||||
~CancelTestTask()
|
||||
{
|
||||
TEST_EQUAL(m_waitDoCall, m_doCalled, ());
|
||||
}
|
||||
|
||||
virtual void Do()
|
||||
{
|
||||
TEST_EQUAL(m_waitDoCall, true, ());
|
||||
m_doCalled = true;
|
||||
threads::Sleep(100);
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_waitDoCall;
|
||||
bool m_doCalled;
|
||||
};
|
||||
}
|
||||
private:
|
||||
bool m_waitDoCall;
|
||||
bool m_doCalled;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
UNIT_TEST(ThreadPool_ExecutionTaskTest)
|
||||
{
|
||||
int finishCounter = 0;
|
||||
Condition cond;
|
||||
base::ThreadPool pool(4, std::bind(&JoinFinishFunction, std::placeholders::_1,
|
||||
std::ref(finishCounter), std::ref(cond)));
|
||||
base::ThreadPool pool(4,
|
||||
std::bind(&JoinFinishFunction, std::placeholders::_1, std::ref(finishCounter), std::ref(cond)));
|
||||
|
||||
for (int i = 0; i < TASK_COUNT - 1; ++i)
|
||||
pool.PushBack(new CancelTestTask(true));
|
||||
@@ -102,7 +85,7 @@ UNIT_TEST(ThreadPool_ExecutionTaskTest)
|
||||
pool.PushBack(p);
|
||||
p->Cancel();
|
||||
|
||||
while(true)
|
||||
while (true)
|
||||
{
|
||||
std::unique_lock lock(cond.m);
|
||||
if (finishCounter == TASK_COUNT)
|
||||
@@ -115,8 +98,8 @@ UNIT_TEST(ThreadPool_EmptyTest)
|
||||
{
|
||||
int finishCouter = 0;
|
||||
Condition cond;
|
||||
base::ThreadPool pool(4, std::bind(&JoinFinishFunction, std::placeholders::_1,
|
||||
std::ref(finishCouter), std::ref(cond)));
|
||||
base::ThreadPool pool(4,
|
||||
std::bind(&JoinFinishFunction, std::placeholders::_1, std::ref(finishCouter), std::ref(cond)));
|
||||
|
||||
threads::Sleep(100);
|
||||
pool.Stop();
|
||||
|
||||
Reference in New Issue
Block a user