X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/a5cb4cf37e5dfa9bb9ce5c5e4ccf8d5978d3576f..a500fb72810060e52d87ad2c2e4691531f0bcc5a:/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp diff --git a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp index 3f47f24b..a63478bd 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp @@ -102,13 +102,7 @@ int STG_CONFIG::Start() 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; } @@ -119,6 +113,7 @@ int STG_CONFIG::Stop() return 0; config.Stop(); + m_thread.request_stop(); //5 seconds to thread stops itself for (size_t i = 0; i < 25; ++i) @@ -131,23 +126,20 @@ int STG_CONFIG::Stop() } if (isRunning) - return -1; + m_thread.detach(); 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(d); - stgConf.isRunning = true; - - stgConf.config.Run(); + isRunning = true; - stgConf.isRunning = false; + config.Run(token); - return NULL; + isRunning = false; }