]> git.tdb.fi Git - libs/core.git/blob - source/core/thread.cpp
Move accessors of static data members to .cpp files
[libs/core.git] / source / core / thread.cpp
1 #include "except.h"
2 #include "thread.h"
3 #include "thread_private.h"
4
5 using namespace std;
6
7 namespace Msp {
8
9 Thread::Thread(const string &name):
10         _priv(new Private),
11         _name(name)
12 { }
13
14 Thread::~Thread()
15 {
16         kill();
17         join();
18         delete _priv;
19 }
20
21 void Thread::join()
22 {
23         if(_state>=JOINED)
24                 return;
25
26         platform_join();
27         _state = JOINED;
28 }
29
30 void Thread::kill()
31 {
32         if(_state!=RUNNING)
33                 return;
34
35         platform_kill();
36         _state = KILLED;
37 }
38
39 void Thread::launch()
40 {
41         if(_state>=RUNNING)
42                 throw already_called("Thread::launch");
43
44         platform_launch();
45         _state = RUNNING;
46 }
47
48 ThreadReturn THREAD_CALL Thread::Private::main_wrapper(void *arg)
49 {
50         Thread *thread = reinterpret_cast<Thread *>(arg);
51         thread->platform_setname();
52         thread->main();
53         thread->_state = FINISHED;
54         return 0;
55 }
56
57 } // namespace Msp