1
0
Fork 0

use an atomic to control thread-enabled

This commit is contained in:
Kevin Matz 2023-05-21 10:04:38 -04:00
parent 50f3145f9e
commit 188a403726
2 changed files with 4 additions and 6 deletions

View File

@ -36,7 +36,7 @@ namespace sACN {
* @param source
* @param universe
*/
UniverseSender::UniverseSender(Source * source, Universe * universe)
UniverseSender::UniverseSender(Source *source, Universe *universe)
: mSource(source)
, mUniverse(universe)
, terminated_resend(3)
@ -113,10 +113,7 @@ void UniverseSender::flush()
*/
void UniverseSender::kill()
{
{
std::unique_lock lk_ctl(mtx_control);
enabled_ = false;
}
enabled_ = false;
flush();
}

View File

@ -26,6 +26,7 @@
#include "data.h"
#include "dmp.h"
#include "../dmx/universe.h"
#include <atomic>
#include <condition_variable>
#include <memory>
#include <thread>
@ -81,9 +82,9 @@ private:
/// > intervals of between 800mS and 1000mS.
const std::chrono::milliseconds keep_alive_interval;
volatile bool enabled_;
mutable std::shared_mutex mtx_control;
mutable std::mutex mtx_thread_;
std::atomic<bool> enabled_;
std::condition_variable_any request_;
std::thread worker_;
void loop_();