ss928_framework/libapi/thead/SafeThread.cpp
2024-12-16 13:31:45 +08:00

48 lines
943 B
C++
Executable File

#include "UmThread.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <atlbase.h>
#include<sys/timeb.h>
UmThread::UmThread(IRunnable* runnable)
: mIsRunning(false), mpRunnable(runnable) {
}
UmThread::~UmThread() {
delete mpRunnable;
}
UINT UmThread::ThreadFunc(LPVOID lpParam) {
UmThread* pThread = (UmThread*)lpParam;
if (pThread == NULL) {
return -1;
}
pThread->mIsRunning = true;
pThread->OnRun();
pThread->mIsRunning = false;
return 0;
}
int UmThread::Start() {
mHandle = CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE)ThreadFunc, (VOID*)this,
0, &mThreadID);
::CloseHandle(mHandle); // http://guanyue7613.blog.163.com/blog/static/885147420127353735454/
return 0;
}
int UmThread::Stop() {
return 0;
}
void UmThread::OnRun() {
if (mpRunnable == 0) { return ; }
mpRunnable->OnRun();
};
void UmThread::Sleep(int milliSec) {
::Sleep(milliSec);
}