2022-09-21 05:16:07 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
2021-09-03 05:11:04 +00:00
|
|
|
#include "../ScriptInstance.h"
|
2022-09-21 05:16:07 +00:00
|
|
|
#include "JSIntervalWorker.h"
|
2021-09-03 05:11:04 +00:00
|
|
|
#include "ScriptAPI.h"
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
CJSIntervalWorker::CJSIntervalWorker(CScriptInstance * inst, void * dukObjectHeapPtr, int delayMS, bool bOnce) :
|
2021-09-03 05:11:04 +00:00
|
|
|
CScriptWorker(inst, dukObjectHeapPtr),
|
|
|
|
m_DelayMS(delayMS),
|
|
|
|
m_bOnce(bOnce)
|
|
|
|
{
|
|
|
|
m_hTimerQuitEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
CJSIntervalWorker::~CJSIntervalWorker()
|
|
|
|
{
|
|
|
|
StopWorkerProc();
|
|
|
|
CloseHandle(m_hTimerQuitEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CJSIntervalWorker::WorkerProc()
|
|
|
|
{
|
|
|
|
HANDLE hTimer = CreateWaitableTimer(nullptr, false, nullptr);
|
|
|
|
|
|
|
|
LARGE_INTEGER liTime;
|
|
|
|
liTime.QuadPart = -m_DelayMS * 10000;
|
|
|
|
SetWaitableTimer(hTimer, &liTime, m_DelayMS, nullptr, nullptr, true);
|
|
|
|
|
2022-09-21 05:16:07 +00:00
|
|
|
HANDLE hWaitHandles[] = {hTimer, m_hTimerQuitEvent};
|
2021-09-03 05:11:04 +00:00
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
DWORD nHandle = WaitForMultipleObjects(2, hWaitHandles, FALSE, INFINITE);
|
|
|
|
|
|
|
|
if (nHandle == WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
m_Instance->PostCMethodCall(m_DukObjectHeapPtr, ScriptAPI::js__IntervalContext_invokeFunc);
|
|
|
|
|
|
|
|
if (m_bOnce)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(hTimer);
|
|
|
|
m_Instance->PostCMethodCall(m_DukObjectHeapPtr, ScriptAPI::js__IntervalContext_remove);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CJSIntervalWorker::StopWorkerProc()
|
|
|
|
{
|
|
|
|
SetEvent(m_hTimerQuitEvent);
|
|
|
|
CScriptWorker::StopWorkerProc();
|
|
|
|
}
|