1 #include <lib/base/thread.h>
5 #include <lib/base/eerror.h>
7 void eThread::thread_completed(void *ptr)
9 eThread *p = (eThread*) ptr;
10 eDebug("thread has completed..");
15 void *eThread::wrapper(void *ptr)
17 eThread *p = (eThread*)ptr;
19 pthread_cleanup_push( thread_completed, (void*)p );
22 pthread_cleanup_pop(0);
27 :the_thread(0), alive(0)
31 void eThread::run( int prio, int policy )
35 eDebug("thread already running !!");
39 pthread_attr_init(&attr);
43 p.__sched_priority=prio;
44 pthread_attr_setschedpolicy(&attr, policy );
45 pthread_attr_setschedparam(&attr, &p);
47 if ( pthread_create(&the_thread, &attr, wrapper, this) )
49 eDebug("couldn't create new thread");
52 pthread_attr_destroy(&attr);
55 while(!alive && timeout--)
57 eDebug("waiting for thread start...");
61 eDebug("thread couldn't be started !!!");
69 void eThread::sendSignal(int sig)
72 pthread_kill( the_thread, sig );
74 eDebug("send signal to non running thread");
77 void eThread::kill(bool sendcancel)
81 if ( alive && sendcancel )
83 eDebug("send cancel to thread");
84 pthread_cancel(the_thread);
86 eDebug("thread joined %d", pthread_join(the_thread, 0));