34 lines
883 B
C++
34 lines
883 B
C++
#include "TestTimeOut.h"
|
|
#include "Log.h"
|
|
#include "MainThread.h"
|
|
#include <thread>
|
|
constexpr int TIMER_SLEEP_MS = 100;
|
|
TestTimeOut::TestTimeOut(const unsigned int &timeOutMs) : mTimeOutMs(timeOutMs)
|
|
{
|
|
mRuning = false;
|
|
mSleepingTime = 0;
|
|
}
|
|
void TestTimeOut::StartTimer(void)
|
|
{
|
|
auto timerThread = [](std::shared_ptr<TestTimeOut> timer)
|
|
{
|
|
timer->Timer();
|
|
};
|
|
std::thread pThread(timerThread, shared_from_this());
|
|
pThread.detach();
|
|
}
|
|
void TestTimeOut::Timer(void)
|
|
{
|
|
mRuning = true;
|
|
while (mRuning)
|
|
{
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(TIMER_SLEEP_MS));
|
|
mSleepingTime += TIMER_SLEEP_MS;
|
|
if (mSleepingTime >= mTimeOutMs)
|
|
{
|
|
LogInfo("Test time out.\n");
|
|
mRuning = false;
|
|
MainThread::GetInstance()->Exit();
|
|
}
|
|
}
|
|
} |