12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #ifndef __RUNNABLE__HH
- #define __RUNNABLE__HH
- #include <thread>
- #include <cstdint>
- #include <cstdio>
- #include <cstdlib>
- #include <string>
- #include <iostream>
- #include <exception>
- 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
|