]> SALOME platform Git repositories - modules/yacs.git/blob - src/bases/ThreadPT.cxx
Salome HOME
a6e78bf0ff18524d8c993fdf2ba9e43cc88c8959
[modules/yacs.git] / src / bases / ThreadPT.cxx
1 #include "ThreadPT.hxx"
2 #include "Exception.hxx"
3 #include <unistd.h>
4
5 using namespace YACS::BASES;
6
7 ThreadPT::ThreadPT(ThreadJob funcPtr, void *stack)
8 {
9   int err;
10   void **stackT=(void **) stack;
11   err=pthread_create(&_threadId,0,funcPtr,stackT);
12   if(err!=0)throw Exception("Error in thread creation");
13 }
14
15 bool ThreadPT::operator==(const ThreadPT& other)
16 {
17   return pthread_equal(_threadId, other._threadId) != 0;
18 }
19
20 //! Detach thread to release resources on exit
21 void ThreadPT::detach()
22 {
23   pthread_detach(pthread_self());
24 }
25
26 void ThreadPT::exit(void *what)
27 {
28   pthread_exit(what);
29 }
30
31 void ThreadPT::join()
32 {
33   void *ret;
34   pthread_join(_threadId, &ret);
35 }
36
37 void ThreadPT::sleep(unsigned long usec)
38 {
39   usleep(usec);
40 }