return -1;
}
- if (pthread_create(&thread, NULL, Run, this))
- {
- errorStr = std::string("Cannot create thread: '") + strerror(errno) + "'.";
- printfd(__FILE__, "%s\n", errorStr.c_str());
- logger(errorStr);
- return -1;
- }
+ m_thread = std::jthread([this](auto token){ Run(token); });
return 0;
}
return 0;
config.Stop();
+ m_thread.request_stop();
//5 seconds to thread stops itself
for (size_t i = 0; i < 25; ++i)
}
if (isRunning)
- return -1;
+ m_thread.detach();
+ else
+ m_thread.join();
return 0;
}
//-----------------------------------------------------------------------------
-void * STG_CONFIG::Run(void * d)
+void STG_CONFIG::Run(std::stop_token token)
{
sigset_t signalSet;
sigfillset(&signalSet);
pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
- STG_CONFIG & stgConf = *static_cast<STG_CONFIG *>(d);
- stgConf.isRunning = true;
-
- stgConf.config.Run();
+ isRunning = true;
- stgConf.isRunning = false;
+ config.Run(token);
- return NULL;
+ isRunning = false;
}