46 lines
854 B
C++
Executable File
46 lines
854 B
C++
Executable File
/*
|
|
**************************************************************************************
|
|
* Filename: SafeThread.h
|
|
* Description: header file
|
|
*
|
|
* Version: 1.0
|
|
* Created:
|
|
* Author:
|
|
*
|
|
* Revision: initial draft;
|
|
**************************************************************************************
|
|
*/
|
|
#pragma once
|
|
#include <thread>
|
|
|
|
class IRunnable {
|
|
public:
|
|
virtual void OnRun() = 0;
|
|
};
|
|
|
|
class SafeThread {
|
|
public:
|
|
SafeThread(IRunnable* runnable = NULL);
|
|
virtual ~SafeThread();
|
|
|
|
public:
|
|
int Start();
|
|
bool IsRunning() const { return mIsRunning; };
|
|
|
|
protected:
|
|
int Stop();
|
|
|
|
public:
|
|
static void Sleep(int millSec);
|
|
|
|
public:
|
|
virtual void OnRun();
|
|
|
|
private:
|
|
static UINT ThreadFunc(LPVOID lpParam);
|
|
HANDLE mHandle;
|
|
DWORD mThreadID;
|
|
IRunnable* mpRunnable;
|
|
bool mIsRunning;
|
|
};
|