Subversion Repositories HomeAutomation

Rev

Rev 1309 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

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