namespace PThread\r
{\r
\r
+void Sleep(const long ms)\r
+{\r
+ pthread_cond_t c;\r
+ pthread_mutex_t m;\r
+ timespec t;\r
+ timeb tb;\r
+\r
+ pthread_mutex_init(&m,NULL);\r
+ pthread_cond_init(&c,NULL);\r
+\r
+ ftime(&tb);\r
+\r
+ t.tv_sec=tb.time+(ms/1000);\r
+ t.tv_nsec=((1000000L)*(long)tb.millitm)+((1000000L)*(ms%1000));\r
+\r
+ pthread_mutex_lock(&m);\r
+ pthread_cond_timedwait(&c,&m,&t);\r
+ pthread_mutex_unlock(&m);\r
+\r
+ pthread_cond_destroy(&c);\r
+ pthread_mutex_destroy(&m);\r
+}\r
+\r
Thread::Thread()\r
{\r
m_running=false;\r
m_cancelled=false;\r
m_runnable=0;\r
m_threadnum=0;\r
+ m_threadcleaned=true;\r
}\r
\r
Thread::Thread(Runnable *runnable)\r
m_cancelled=false;\r
m_runnable=runnable;\r
m_threadnum=0;\r
+ m_threadcleaned=true;\r
if(m_runnable)\r
{\r
m_runnable->m_thread=this;\r
{\r
Cancel();\r
Join();\r
+ if(m_threadcleaned==false)\r
+ {\r
+ pthread_detach(m_thread);\r
+ }\r
if(m_runnable)\r
{\r
delete m_runnable;\r
if(m_running)\r
{\r
pthread_join(m_thread,NULL);\r
+ m_threadcleaned=true;\r
}\r
}\r
\r
pthread_mutex_lock(&m);\r
pthread_cond_timedwait(&c,&m,&t);\r
pthread_mutex_unlock(&m);\r
+\r
+ pthread_cond_destroy(&c);\r
+ pthread_mutex_destroy(&m);\r
}\r
}\r
\r
void Thread::Start()\r
{\r
m_running=true;\r
+ m_threadcleaned=false;\r
m_threadnum=pthread_create(&m_thread,NULL,Thread::EntryPoint,this);\r
}\r
\r