diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2017-01-22 12:03:22 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2017-01-22 12:03:22 -0500 |
commit | fa341a962e351de9efba3cd6d3dccb582b625721 (patch) | |
tree | 08a0bd1caed82b2fb8d296f79f87dbd993b0cbc9 /include/thread.hpp | |
parent | d543982669364f66fc797f78aa2d604db4bc4325 (diff) |
windows
Diffstat (limited to 'include/thread.hpp')
-rw-r--r-- | include/thread.hpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/include/thread.hpp b/include/thread.hpp new file mode 100644 index 0000000..3adc43d --- /dev/null +++ b/include/thread.hpp @@ -0,0 +1,36 @@ +#ifndef THREAD_HPP_ +#define THREAD_HPP_ + +#ifndef __WIN32__ +#include <thread> +#else +#include <win32thread.hpp> +#endif // __WIN32__ + +#include <atomic> +#include <entityx/entityx.h> + +class GameThread : public entityx::Receiver<GameThread> { +private: + std::atomic_bool die; + std::thread thread; + +public: + GameThread(std::function<void(void)> func) { + die.store(false); + thread = std::thread([&](std::function<void(void)> f) { + while (!die.load()) + f(); + }, func); + } + + ~GameThread(void) { + thread.join(); + } + + inline void stop(void) { + die.store(true); + } +}; + +#endif // THREAD_HPP_
\ No newline at end of file |