use the volatile global enabled flag
This commit is contained in:
parent
37367cb6b4
commit
52758cc904
|
@ -43,7 +43,7 @@ UniverseSender::UniverseSender(Source * source, Universe * universe)
|
|||
, minimum_update_time(22700)
|
||||
, retransmission_count(0)
|
||||
, keep_alive_interval(800)
|
||||
, enable_(true)
|
||||
, enabled_(true)
|
||||
, last_data_({0})
|
||||
, dmp_(std::make_shared<ACN::DMP::Pdu>())
|
||||
, frame_(std::make_shared<DATA::Pdu>())
|
||||
|
@ -115,7 +115,7 @@ void UniverseSender::kill()
|
|||
{
|
||||
{
|
||||
std::unique_lock lk_ctl(mtx_control);
|
||||
enable_ = false;
|
||||
enabled_ = false;
|
||||
}
|
||||
flush();
|
||||
}
|
||||
|
@ -126,7 +126,6 @@ void UniverseSender::kill()
|
|||
*/
|
||||
void UniverseSender::loop_()
|
||||
{
|
||||
bool enabled = true; // at least 1 loop
|
||||
bool new_data;
|
||||
std::chrono::nanoseconds elapsed;
|
||||
std::chrono::microseconds sleep;
|
||||
|
@ -134,20 +133,14 @@ void UniverseSender::loop_()
|
|||
|
||||
update_dmp_(); // initial data segment
|
||||
|
||||
while (enabled || terminated_resend > 0)
|
||||
while (enabled_ || terminated_resend > 0)
|
||||
{
|
||||
// enforce strict minimum update times
|
||||
elapsed = std::chrono::system_clock::now() - mUniverse->last_updated_;
|
||||
if (elapsed < minimum_update_time)
|
||||
std::this_thread::sleep_for(minimum_update_time - elapsed);
|
||||
|
||||
// check for control permission to continue looping
|
||||
{
|
||||
std::shared_lock lk_ctl(mtx_control);
|
||||
enabled = enable_;
|
||||
}
|
||||
|
||||
if (enable_)
|
||||
if (enabled_)
|
||||
{
|
||||
mUniverse->setStatus(Universe::DMX_ACTIVE);
|
||||
std::shared_lock lk_data(mUniverse->mtx_data);
|
||||
|
|
|
@ -81,7 +81,7 @@ private:
|
|||
/// > intervals of between 800mS and 1000mS.
|
||||
const std::chrono::milliseconds keep_alive_interval;
|
||||
|
||||
bool enable_;
|
||||
volatile bool enabled_;
|
||||
mutable std::shared_mutex mtx_control;
|
||||
mutable std::mutex mtx_thread_;
|
||||
std::condition_variable_any request_;
|
||||
|
|
Loading…
Reference in New Issue