1 #include "../../include/pthreadwrapper/thread.h"
\r
3 #include <sys/timeb.h>
\r
12 void Sleep(const long ms)
\r
19 pthread_mutex_init(&m,NULL);
\r
20 pthread_cond_init(&c,NULL);
\r
24 t.tv_sec=tb.time+(ms/1000);
\r
25 t.tv_nsec=((1000000L)*(long)tb.millitm)+((1000000L)*(ms%1000));
\r
27 pthread_mutex_lock(&m);
\r
28 pthread_cond_timedwait(&c,&m,&t);
\r
29 pthread_mutex_unlock(&m);
\r
40 Thread::Thread(Runnable *runnable)
\r
44 m_runnable=runnable;
\r
48 m_runnable->m_thread=this;
\r
63 void Thread::Cancel()
\r
71 void *Thread::EntryPoint(void *pthis)
\r
75 ((Thread *)pthis)->m_runnable->Run();
\r
76 ((Thread *)pthis)->m_running=false;
\r
77 ((Thread *)pthis)->m_cancelled=false;
\r
79 ((Thread *)pthis)->m_threadnum=0;
\r
87 pthread_join(m_thread,NULL);
\r
91 void Thread::Sleep(const long ms)
\r
100 pthread_mutex_init(&m,NULL);
\r
101 pthread_cond_init(&c,NULL);
\r
105 t.tv_sec=tb.time+(ms/1000);
\r
106 t.tv_nsec=((1000000L)*(long)tb.millitm)+((1000000L)*(ms%1000));
\r
108 pthread_mutex_lock(&m);
\r
109 pthread_cond_timedwait(&c,&m,&t);
\r
110 pthread_mutex_unlock(&m);
\r
114 void Thread::Start()
\r
117 m_threadnum=pthread_create(&m_thread,NULL,Thread::EntryPoint,this);
\r