diff options
Diffstat (limited to 'src/utility.h')
-rw-r--r-- | src/utility.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/utility.h b/src/utility.h index f7e726f87..e4494948c 100644 --- a/src/utility.h +++ b/src/utility.h @@ -28,9 +28,18 @@ with this program; if not, write to the Free Software Foundation, Inc., #include <fstream> #include <string> #include <sstream> +#include <jthread.h> #include <jmutex.h> #include <jmutexautolock.h> +#ifdef _WIN32 + #include <windows.h> + #define sleep_ms(x) Sleep(x) +#else + #include <unistd.h> + #define sleep_ms(x) usleep(x*1000) +#endif + #include "common_irrlicht.h" #include "debug.h" #include "strfnd.h" @@ -1100,5 +1109,43 @@ private: JMutex m_mutex; }; +class SimpleThread : public JThread +{ + bool run; + JMutex run_mutex; + +public: + + SimpleThread(): + JThread(), + run(true) + { + run_mutex.Init(); + } + + virtual ~SimpleThread() + {} + + virtual void * Thread() = 0; + + bool getRun() + { + JMutexAutoLock lock(run_mutex); + return run; + } + void setRun(bool a_run) + { + JMutexAutoLock lock(run_mutex); + run = a_run; + } + + void stop() + { + setRun(false); + while(IsRunning()) + sleep_ms(100); + } +}; + #endif |