26 #include "../system/log.h"
37 : mCancelThread(false),
120 std::this_thread::sleep_for(
121 std::chrono::microseconds(static_cast<int>(1000*milliseconds)));
166 #if defined(__linux__) and not defined(QT_NO_DEBUG) and not defined(__ANDROID__)
169 pthread_setname_np (pthread_self(), s.c_str());
193 LogE(
"Worker thread stopped with EptException: %s", e.
what());
196 catch (
const std::exception &e)
198 LogE(
"Worker thread stopped with std::exception: %s", e.what());
201 LogE(
"Worker thread stopped with an unknown exception");
virtual void stop()
Stop the thread.
bool mCancelThread
Cancel flag.
const char * what() const
Override std::exception::what.
void msleep(double milliseconds)
Sleep function for staying idle.
SimpleThreadHandler()
Constructor.
virtual void exceptionCaught(const EptException &e)
EPT exception handling.
virtual ~SimpleThreadHandler()
virtual destructor calls stop
bool isThreadRunning() const
Flag to check if the thread is running.
static void setThreadName(std::string s)
Specify the name of the thread.
std::thread mThread
Local thread member variable.
virtual void start()
Start the thread.
void simpleWorkerFunction()
Private helper function.
void setCancelThread(bool b)
Cancel-flag setter method, thread-safe.
std::mutex mLockMutex
Mutex protecting the cancel flag.
std::atomic< bool > mRunning
Is the thread running.
virtual void workerFunction()=0
Virtual worker function, executed within the new thread.
bool cancelThread() const
Cancel-flag getter method, thread-safe.