DragonNest/Client/EtFileSystemTool/Thread.cpp
2024-12-20 16:56:44 +08:00

61 lines
No EOL
2.1 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "stdafx.h"
#include "Thread.h"
Thread::Thread()
: m_nThreadID( 0 ), m_hHandleThread( INVALID_HANDLE_VALUE )
{
}
Thread::~Thread()
{
m_bThreadLoop = false;
}
bool
Thread::Start()
{
if( m_hHandleThread != INVALID_HANDLE_VALUE )
return false;
m_hHandleThread = ::CreateThread( 0, 0, _Runner, ( LPVOID )this, 0, &m_nThreadID );
if( m_hHandleThread == 0 )
return false;
m_bThreadLoop = true;
return true;
}
bool
Thread::Terminate( DWORD nExitCode )
{
bool ret;
if( m_hHandleThread == INVALID_HANDLE_VALUE )
return true;
ret = ( ::TerminateThread( m_hHandleThread, nExitCode ) == TRUE );
m_hHandleThread = INVALID_HANDLE_VALUE;
return ret;
}
bool
Thread::WaitForTerminate( DWORD nTimeout )
{
if( m_hHandleThread == INVALID_HANDLE_VALUE )
return false;
return ( ::WaitForSingleObject( m_hHandleThread, nTimeout ) == WAIT_OBJECT_0 );
}
DWORD WINAPI
Thread::_Runner( LPVOID pParam )
{
Thread* pInstance = static_cast<Thread*>( pParam );
pInstance->Run();
return 0;
}