use locking guards
This commit is contained in:
parent
f1d3fe0256
commit
d11e136247
|
@ -39,10 +39,10 @@ UniverseSender::UniverseSender(Source * source, Universe * universe)
|
|||
, mUniverse(universe)
|
||||
, terminated_resend(3)
|
||||
, minimum_update_time(22700)
|
||||
, last_null_data({0})
|
||||
, retransmission_count(0)
|
||||
, keep_alive_interval(800)
|
||||
, enable_(true)
|
||||
, last_data_({0})
|
||||
, dmp_(std::make_shared<ACN::DMP::Pdu>())
|
||||
, frame_(std::make_shared<DATA::Pdu>())
|
||||
{
|
||||
|
@ -95,7 +95,9 @@ bool UniverseSender::isSending()
|
|||
|
||||
|
||||
/**
|
||||
* @brief UniverseSender::flush
|
||||
* @brief Wake up and send a frame of sACN.
|
||||
*
|
||||
*
|
||||
*/
|
||||
void UniverseSender::flush()
|
||||
{
|
||||
|
@ -108,9 +110,10 @@ void UniverseSender::flush()
|
|||
*/
|
||||
void UniverseSender::kill()
|
||||
{
|
||||
control_mutex_.lock();
|
||||
enable_ = false;
|
||||
control_mutex_.unlock();
|
||||
{
|
||||
std::unique_lock lk_ctl(mtx_control_);
|
||||
enable_ = false;
|
||||
}
|
||||
flush();
|
||||
}
|
||||
|
||||
|
@ -124,7 +127,7 @@ void UniverseSender::loop_()
|
|||
bool new_data;
|
||||
std::chrono::nanoseconds elapsed;
|
||||
std::chrono::microseconds sleep;
|
||||
std::mutex mtx; // std::conditional_variable requires in the sleeping thread. Why??
|
||||
std::unique_lock lk_thread(mtx_thread_);
|
||||
|
||||
while (enabled || terminated_resend > 0)
|
||||
{
|
||||
|
@ -134,9 +137,10 @@ void UniverseSender::loop_()
|
|||
std::this_thread::sleep_for(minimum_update_time - elapsed);
|
||||
|
||||
// check for control permission to continue looping
|
||||
control_mutex_.lock();
|
||||
enabled = enable_;
|
||||
control_mutex_.unlock();
|
||||
{
|
||||
std::shared_lock lk_ctl(mtx_control_);
|
||||
enabled = enable_;
|
||||
}
|
||||
|
||||
if (enable_)
|
||||
{
|
||||
|
@ -175,7 +179,7 @@ void UniverseSender::loop_()
|
|||
mUniverse->metadata_->sequence_number++;
|
||||
|
||||
// sleep before the next cycle
|
||||
request_.wait_for(mtx, sleep);
|
||||
request_.wait_for(lk_thread, sleep);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,6 @@ private:
|
|||
/// > 1. Three packets containing the non-changing Property Values
|
||||
/// > (corresponding to DMX512-A slot data) shall be sent before the
|
||||
/// > initiation of transmission suppression.
|
||||
DMX::DimmerData last_null_data;
|
||||
unsigned int retransmission_count;
|
||||
|
||||
/// > 2. Thereafter, a single keep-alive packet shall be transmitted at
|
||||
|
@ -83,13 +82,15 @@ private:
|
|||
std::chrono::milliseconds keep_alive_interval;
|
||||
|
||||
bool enable_;
|
||||
std::mutex control_mutex_;
|
||||
mutable std::shared_mutex mtx_control_;
|
||||
mutable std::mutex mtx_thread_;
|
||||
std::condition_variable_any request_;
|
||||
std::thread worker_;
|
||||
void loop_();
|
||||
|
||||
void update_dmp_();
|
||||
DMX::DimmerData last_data_;
|
||||
ACN::PDU::Message<ACN::DMP::Pdu> dmp_;
|
||||
void update_dmp_();
|
||||
|
||||
ACN::PDU::Message<DATA::Pdu> frame_;
|
||||
void dataFrameSender(ACN::PDU::Message<ACN::DMP::Pdu>) const;
|
||||
|
|
Loading…
Reference in New Issue