use an atomic to control thread-enabled
This commit is contained in:
parent
50f3145f9e
commit
188a403726
|
@ -36,7 +36,7 @@ namespace sACN {
|
||||||
* @param source
|
* @param source
|
||||||
* @param universe
|
* @param universe
|
||||||
*/
|
*/
|
||||||
UniverseSender::UniverseSender(Source * source, Universe * universe)
|
UniverseSender::UniverseSender(Source *source, Universe *universe)
|
||||||
: mSource(source)
|
: mSource(source)
|
||||||
, mUniverse(universe)
|
, mUniverse(universe)
|
||||||
, terminated_resend(3)
|
, terminated_resend(3)
|
||||||
|
@ -113,10 +113,7 @@ void UniverseSender::flush()
|
||||||
*/
|
*/
|
||||||
void UniverseSender::kill()
|
void UniverseSender::kill()
|
||||||
{
|
{
|
||||||
{
|
enabled_ = false;
|
||||||
std::unique_lock lk_ctl(mtx_control);
|
|
||||||
enabled_ = false;
|
|
||||||
}
|
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "dmp.h"
|
#include "dmp.h"
|
||||||
#include "../dmx/universe.h"
|
#include "../dmx/universe.h"
|
||||||
|
#include <atomic>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
@ -81,9 +82,9 @@ private:
|
||||||
/// > intervals of between 800mS and 1000mS.
|
/// > intervals of between 800mS and 1000mS.
|
||||||
const std::chrono::milliseconds keep_alive_interval;
|
const std::chrono::milliseconds keep_alive_interval;
|
||||||
|
|
||||||
volatile bool enabled_;
|
|
||||||
mutable std::shared_mutex mtx_control;
|
mutable std::shared_mutex mtx_control;
|
||||||
mutable std::mutex mtx_thread_;
|
mutable std::mutex mtx_thread_;
|
||||||
|
std::atomic<bool> enabled_;
|
||||||
std::condition_variable_any request_;
|
std::condition_variable_any request_;
|
||||||
std::thread worker_;
|
std::thread worker_;
|
||||||
void loop_();
|
void loop_();
|
||||||
|
|
Loading…
Reference in New Issue