#ifndef __RUNNABLE__HH #define __RUNNABLE__HH #include #include #include #include #include #include #include class CRunnable { private: enum THREAD_STATUS { RUNNING, SUSPENDED, STOPPED }; public: CRunnable(const std::string threadName = "noNamed"); ~CRunnable() {} bool Start(bool suspend = false); int Join(int timeout = -1); public: virtual void Run() = 0; public: bool isRunning() { return (RUNNING == status); } bool isSuspended() { return (SUSPENDED == status); } bool isStopped() { return (STOPPED == status); } bool isAlive() { return (STOPPED != status); } THREAD_STATUS getStatus() { return status; }; private: void setStatus(THREAD_STATUS status) { this->status = status; } static void staticThreadFunc(void* arg); protected: std::thread* m_pthread; volatile THREAD_STATUS status; }; #endif