Austin Schuh | 9b360e9 | 2013-03-27 04:47:04 +0000 | [diff] [blame] | 1 | #ifndef THREAD_H_ |
| 2 | #define THREAD_H_ |
| 3 | |
| 4 | #include <sys/socket.h> |
| 5 | #include <linux/can.h> |
| 6 | #include <boost/thread/locks.hpp> |
| 7 | #include <boost/thread.hpp> |
| 8 | |
| 9 | class Thread { |
| 10 | public: |
| 11 | // Constructer initializes terminate to false. |
| 12 | Thread() : should_terminate_(false) {} |
| 13 | |
| 14 | // Terminate the thread soon. |
| 15 | void Terminate(); |
| 16 | |
| 17 | protected: |
| 18 | // Helper method to atomically read the should_terminate_ boolean. |
| 19 | bool should_run(); |
| 20 | |
| 21 | private: |
| 22 | // Stores whether or not the thread has been asked to quit. |
| 23 | // TODO(aschuh): This really should be a Notification... |
| 24 | bool should_terminate_; |
| 25 | // Mutex to protect should_terminate. |
| 26 | boost::mutex terminate_mutex_; |
| 27 | }; |
| 28 | |
| 29 | #endif // THREAD_H_ |