Subversion Repositories HomeAutomation

Rev

Rev 1309 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1309 Rev 1317
Line 4... Line 4...
4
 *  Created on: Apr 26, 2009
4
 *  Created on: Apr 26, 2009
5
 *      Author: Mattias Runge
5
 *      Author: Mattias Runge
6
 */
6
 */
7
 
7
 
8
#include "Thread.h"
8
#include "Thread.h"
9
#include <iostream>
-
 
10
 
9
 
11
using namespace std;
10
using namespace std;
12
 
11
 
13
namespace atom {
12
namespace atom {
14
namespace utils {
13
namespace thread {
15
 
14
 
16
Thread::Thread()
15
Thread::Thread()
17
{
16
{
18
    this->_running = false;
17
    this->myIsRunning = false;
19
}
18
}
20
 
19
 
21
Thread::~Thread()
20
Thread::~Thread()
22
{
21
{
23
    //cout << "Thread destroy" << endl;
22
    //cout << "Thread destroy" << endl;
24
    this->stop();
23
    this->stop();
25
}
24
}
26
 
25
 
27
void Thread::start()
26
void Thread::start()
28
{
27
{
29
    if (!this->_running)
28
    if (!this->myIsRunning)
30
    {
29
    {
31
        boost::thread localThread(boost::bind(&Thread::runBase, this));
30
        boost::thread localThread(boost::bind(&Thread::runBase, this));
32
        this->_thread = localThread.move();
31
        this->myThread = localThread.move();
33
        this->_running = true;
32
        this->myIsRunning = true;
34
    }
33
    }
35
}
34
}
36
 
35
 
37
void Thread::stop()
36
void Thread::stop()
38
{
37
{
39
    this->_thread.interrupt();
38
    this->myThread.interrupt();
40
    this->_thread.join();
39
    this->myThread.join();
41
    this->_running = false;
40
    this->myIsRunning = false;
42
}
41
}
43
 
42
 
44
boost::thread::id Thread::getId()
43
boost::thread::id Thread::getId()
45
{
44
{
46
    return this->_thread.get_id();
45
    return this->myThread.get_id();
47
}
46
}
48
 
47
 
49
bool Thread::isRunning()
48
bool Thread::isRunning()
50
{
49
{
51
    return this->_running;
50
    return this->myIsRunning;
52
}
51
}
53
 
52
 
54
void Thread::runBase()
53
void Thread::runBase()
55
{
54
{
56
    this->_running = true;
55
    this->myIsRunning = true;
57
    this->run();
56
    this->run();
58
    this->_running = false;
57
    this->myIsRunning = false;
59
}
58
}
60
 
59
 
61
void Thread::run()
60
void Thread::run()
62
{
61
{
63
}
62
}