ss928_framework/libapi/thead/SafeThread.h

46 lines
854 B
C
Raw Normal View History

2024-12-16 13:31:45 +08:00
/*
**************************************************************************************
* 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;
};