1
0

Refactoring

This commit is contained in:
Scott E. Graves
2017-02-18 10:15:01 -06:00
parent bac3fad30c
commit 3949ba30e1
11 changed files with 193 additions and 102 deletions

View File

@@ -0,0 +1,43 @@
#include "stdafx.h"
#include "AutoThread.h"
using namespace Sia::Api;
CAutoThread::CAutoThread(const CSiaCurl& siaCurl) :
_siaCurl(siaCurl.GetHostConfig()),
_stopEvent(::CreateEvent(nullptr, FALSE, FALSE, nullptr))
{
}
CAutoThread::~CAutoThread()
{
StopAutoThread();
::CloseHandle(_stopEvent);
}
void CAutoThread::StartAutoThread()
{
std::lock_guard<std::mutex> l(_startStopMutex);
if (!_thread)
{
_thread.reset(new std::thread([this]() {
do
{
AutoThreadCallback(_siaCurl);
} while (::WaitForSingleObject(_stopEvent, 2000) == WAIT_TIMEOUT);
}));
}
}
void CAutoThread::StopAutoThread()
{
std::lock_guard<std::mutex> l(_startStopMutex);
if (_thread)
{
::SetEvent(_stopEvent);
_thread->join();
_thread.reset(nullptr);
}
}