123456789101112131415161718192021222324252627282930313233343536373839 |
- #include "Runnable.h"
- CRunnable::CRunnable(const std::string threadName/*="noNamed"*/)
- :status(STOPPED)
- ,m_pthread(0)
- {
- }
- bool CRunnable::Start(bool suspend/*=false*/)
- {
- m_pthread = new std::thread(&CRunnable::staticThreadFunc,this);
- return (m_pthread!=0);
- }
- int CRunnable::Join(int timeout /*=-1*/)
- {
- if(m_pthread)
- {
- if(m_pthread->joinable())
- {
- m_pthread->join();
- return 0;
- }
- }
- else
- {
- return -1;
- }
- }
- /*static*/ void CRunnable::staticThreadFunc(void *arg)
- {
- CRunnable* runnable = (CRunnable*)arg;
- runnable->Run();
- }
|