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;
18 p->before_set_thread_alive();
20 pthread_cleanup_push( thread_completed, (void*)p );
23 pthread_cleanup_pop(1);
28 :the_thread(0), alive(0)
32 void eThread::run( int prio, int policy )
36 eDebug("thread already running !!");
40 pthread_attr_init(&attr);
44 p.__sched_priority=prio;
45 pthread_attr_setschedpolicy(&attr, policy );
46 pthread_attr_setschedparam(&attr, &p);
48 if ( pthread_create(&the_thread, &attr, wrapper, this) )
50 eDebug("couldn't create new thread");
53 pthread_attr_destroy(&attr);
56 while(!alive && timeout--)
58 // eDebug("waiting for thread start...");
62 eDebug("thread couldn't be started !!!");
70 void eThread::sendSignal(int sig)
73 pthread_kill( the_thread, sig );
75 eDebug("send signal to non running thread");
78 void eThread::kill(bool sendcancel)
82 if ( alive && sendcancel )
84 eDebug("send cancel to thread");
85 pthread_cancel(the_thread);
87 eDebug("thread joined %d", pthread_join(the_thread, 0));