aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine/Slave.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/Slave.hpp')
-rw-r--r--src/engine/Slave.hpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/engine/Slave.hpp b/src/engine/Slave.hpp
index 55701a7..74ec06b 100644
--- a/src/engine/Slave.hpp
+++ b/src/engine/Slave.hpp
@@ -17,8 +17,9 @@
#ifndef MACHINA_SLAVE_HPP
#define MACHINA_SLAVE_HPP
+#include <thread>
+
#include "raul/Semaphore.hpp"
-#include "raul/Thread.hpp"
namespace machina {
@@ -27,19 +28,19 @@ namespace machina {
* Use this to perform some task in a separate thread you want to 'drive'
* from a realtime (or otherwise) thread.
*/
-class Slave : public Raul::Thread
+class Slave
{
public:
- Slave() : _whip(0) {}
- ~Slave() {
- _exit_flag = true;
- _whip.post();
- }
+ Slave()
+ : _whip(0)
+ , _exit_flag(false)
+ , _thread(&Slave::_run, this)
+ {}
- virtual void join() {
+ virtual ~Slave() {
_exit_flag = true;
_whip.post();
- Thread::join();
+ _thread.join();
}
/** Tell the slave to do whatever work it does. Realtime safe. */
@@ -58,15 +59,13 @@ protected:
private:
inline void _run() {
- while (true) {
- _whip.wait();
- if (_exit_flag) {
- break;
- }
+ while (_whip.wait() && !_exit_flag) {
_whipped();
}
}
+ bool _exit_flag;
+ std::thread _thread;
};
} // namespace machina