Files

39 lines
650 B
C++

#include "dl_thread.h"
#if DL_PLATFORM == DL_PLATFORM_WIN32
#include <Windows.h>
#endif
#include "dl_time.h"
namespace dl
{
ThreadManager* g_thread;
void Thread::Terminate()
{
#if DL_PLATFORM == DL_PLATFORM_WIN32
TerminateThread(_t.native_handle(), -1);
#elif DL_PLATFORM == DL_PLATFORM_LINUX
pthread_cancel(_t.native_handle());
#else
log_damage0("本平台暂未支持中止线程!");
#endif
_state = 1;
}
Thread::~Thread()
{
if (_t.joinable())
_t.join();
while (true)
{
// 必须完成线程后,才能删除自己
if (_state == 1)
break;
g_time->Sleep();
}
g_thread->_remove_ref(this);
}
}