Rev 1317 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1317 | Rev 1403 | ||
|---|---|---|---|
| Line 12... | Line 12... | ||
| 12 | namespace atom { |
12 | namespace atom { |
| 13 | namespace thread { |
13 | namespace thread { |
| 14 | 14 | ||
| 15 | Thread::Thread() |
15 | Thread::Thread() |
| 16 | { |
16 | { |
| 17 | this-> |
17 | this->is_running_ = false; |
| 18 | } |
18 | } |
| 19 | 19 | ||
| 20 | Thread::~Thread() |
20 | Thread::~Thread() |
| 21 | { |
21 | { |
| 22 | //cout << "Thread destroy" << endl; |
22 | //cout << "Thread destroy" << endl; |
| 23 | this-> |
23 | this->Stop(); |
| 24 | } |
24 | } |
| 25 | 25 | ||
| 26 | void Thread:: |
26 | void Thread::Start() |
| 27 | { |
27 | { |
| 28 | if (!this-> |
28 | if (!this->is_running_) |
| 29 | { |
29 | { |
| 30 | boost::thread localThread(boost::bind(&Thread:: |
30 | boost::thread localThread(boost::bind(&Thread::RunBase, this)); |
| 31 | this-> |
31 | this->thread_ = localThread.move(); |
| 32 | this-> |
32 | this->is_running_ = true; |
| 33 | } |
33 | } |
| 34 | } |
34 | } |
| 35 | 35 | ||
| 36 | void Thread:: |
36 | void Thread::Stop() |
| 37 | { |
37 | { |
| 38 | this-> |
38 | this->thread_.interrupt(); |
| 39 | this-> |
39 | this->thread_.join(); |
| 40 | this-> |
40 | this->is_running_ = false; |
| 41 | } |
41 | } |
| 42 | 42 | ||
| 43 | boost::thread::id Thread:: |
43 | boost::thread::id Thread::GetId() |
| 44 | { |
44 | { |
| 45 | return this-> |
45 | return this->thread_.get_id(); |
| 46 | } |
46 | } |
| 47 | 47 | ||
| 48 | bool Thread:: |
48 | bool Thread::IsRunning() |
| 49 | { |
49 | { |
| 50 | return this-> |
50 | return this->is_running_; |
| 51 | } |
51 | } |
| 52 | 52 | ||
| 53 | void Thread:: |
53 | void Thread::RunBase() |
| 54 | { |
54 | { |
| 55 | this-> |
55 | this->is_running_ = true; |
| 56 | this-> |
56 | this->Run(); |
| 57 | this-> |
57 | this->is_running_ = false; |
| 58 | } |
58 | } |
| 59 | 59 | ||
| 60 |
|
60 | } // namespace thread |
| 61 | { |
- | |
| 62 | } |
- | |
| 63 | - | ||
| 64 | } |
61 | } // namespace atom |
| 65 | } |
- | |