Subversion Repositories HomeAutomation

Rev

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

  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 {
  13. namespace thread {
  14.  
  15. Thread::Thread()
  16. {
  17.     this->myIsRunning = false;
  18. }
  19.  
  20. Thread::~Thread()
  21. {
  22.     //cout << "Thread destroy" << endl;
  23.     this->stop();
  24. }
  25.  
  26. void Thread::start()
  27. {
  28.     if (!this->myIsRunning)
  29.     {
  30.         boost::thread localThread(boost::bind(&Thread::runBase, this));
  31.         this->myThread = localThread.move();
  32.         this->myIsRunning = true;
  33.     }
  34. }
  35.  
  36. void Thread::stop()
  37. {
  38.     this->myThread.interrupt();
  39.     this->myThread.join();
  40.     this->myIsRunning = false;
  41. }
  42.  
  43. boost::thread::id Thread::getId()
  44. {
  45.     return this->myThread.get_id();
  46. }
  47.  
  48. bool Thread::isRunning()
  49. {
  50.     return this->myIsRunning;
  51. }
  52.  
  53. void Thread::runBase()
  54. {
  55.     this->myIsRunning = true;
  56.     this->run();
  57.     this->myIsRunning = false;
  58. }
  59.  
  60. void Thread::run()
  61. {
  62. }
  63.  
  64. }
  65. }
  66.