X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Fpthreadwrapper%2Fthread.cpp;h=d08cf332685d09a22311cd86607731009ab6cc11;hp=466dd5c928a4fcda44cb91dfc38a112e7b4c76c1;hb=f60495a029c54358f82956482fe203fe2b7b5b23;hpb=c7fcb4c4bc5012a584add81a9509fc1f84c3c688 diff --git a/src/pthreadwrapper/thread.cpp b/src/pthreadwrapper/thread.cpp index 466dd5c..d08cf33 100644 --- a/src/pthreadwrapper/thread.cpp +++ b/src/pthreadwrapper/thread.cpp @@ -9,11 +9,32 @@ namespace PThread { +void Sleep(const long ms) +{ + pthread_cond_t c; + pthread_mutex_t m; + timespec t; + timeb tb; + + pthread_mutex_init(&m,NULL); + pthread_cond_init(&c,NULL); + + ftime(&tb); + + t.tv_sec=tb.time+(ms/1000); + t.tv_nsec=((1000000L)*(long)tb.millitm)+((1000000L)*(ms%1000)); + + pthread_mutex_lock(&m); + pthread_cond_timedwait(&c,&m,&t); + pthread_mutex_unlock(&m); +} + Thread::Thread() { m_running=false; m_cancelled=false; m_runnable=0; + m_threadnum=0; } Thread::Thread(Runnable *runnable) @@ -21,6 +42,7 @@ Thread::Thread(Runnable *runnable) m_running=false; m_cancelled=false; m_runnable=runnable; + m_threadnum=0; if(m_runnable) { m_runnable->m_thread=this; @@ -54,6 +76,7 @@ void *Thread::EntryPoint(void *pthis) ((Thread *)pthis)->m_running=false; ((Thread *)pthis)->m_cancelled=false; } + ((Thread *)pthis)->m_threadnum=0; return NULL; } @@ -91,7 +114,7 @@ void Thread::Sleep(const long ms) void Thread::Start() { m_running=true; - pthread_create(&m_thread,NULL,Thread::EntryPoint,this); + m_threadnum=pthread_create(&m_thread,NULL,Thread::EntryPoint,this); } } // namespace