Subversion Repositories HomeAutomation

Rev

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