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 pthread_cleanup_push( thread_completed
, (void*)p
);
21 pthread_cleanup_pop(1);
26 :the_thread(0), alive(0)
30 void eThread::run( int prio
, int policy
)
34 eDebug("thread already running !!");
38 pthread_attr_init(&attr
);
42 p
.__sched_priority
=prio
;
43 pthread_attr_setschedpolicy(&attr
, policy
);
44 pthread_attr_setschedparam(&attr
, &p
);
46 if ( pthread_create(&the_thread
, &attr
, wrapper
, this) )
48 eDebug("couldn't create new thread");
59 void eThread::kill(bool sendcancel
)
63 if ( alive
&& sendcancel
)
65 eDebug("send cancel to thread");
66 pthread_cancel(the_thread
);
68 eDebug("thread joined %d", pthread_join(the_thread
, 0));