correct locking semantics

This commit is contained in:
Kevin Matz 2022-12-09 23:09:52 -05:00
parent 8221c90e24
commit eb47f6543f
2 changed files with 20 additions and 17 deletions

View File

@ -139,7 +139,9 @@ void ArbitratingUniverse::deleteSourceUniverse(const DATA::data_header& src)
return; return;
if (sources_.size() == 1 && hold_last_look_) if (sources_.size() == 1 && hold_last_look_)
return; return;
std::unique_lock lk_wctl(lk_ctl); }
{
std::unique_lock lk_ctl(mtx_control);
sources_.erase(src); sources_.erase(src);
} }
doListChangeCallbacks(); doListChangeCallbacks();
@ -187,7 +189,6 @@ std::shared_ptr<void> ArbitratingUniverse::onSourceListChange(std::function<void
*/ */
void ArbitratingUniverse::doListChangeCallbacks() void ArbitratingUniverse::doListChangeCallbacks()
{ {
std::shared_lock lk_ctl(mtx_control);
for (auto it = cb_sourceListChange.begin(); it != cb_sourceListChange.end();) for (auto it = cb_sourceListChange.begin(); it != cb_sourceListChange.end();)
{ {
if (auto sp = it->lock()) if (auto sp = it->lock())
@ -197,7 +198,7 @@ void ArbitratingUniverse::doListChangeCallbacks()
} }
else else
{ // or remove the callback { // or remove the callback
std::unique_lock lk_wctl(lk_ctl); std::unique_lock lk_ctl(mtx_control);
it = cb_sourceListChange.erase(it); it = cb_sourceListChange.erase(it);
} }
} }

View File

@ -95,25 +95,27 @@ bool Universe::isSyncronized()
*/ */
void Universe::synchronize(uint8_t sequence_number) void Universe::synchronize(uint8_t sequence_number)
{ {
std::shared_lock lk_ctl(mtx_control);
if (!sync_data_) if (!sync_data_)
return; return;
int8_t dif;
/// > \cite sACN 6.7.2 Sequence Numbering {
/// > std::shared_lock lk_ctl(mtx_control);
/// > Having first received a packet with sequence number A, /// > \cite sACN 6.7.2 Sequence Numbering
/// > a second packet with sequence number B arrives. /// >
/// > If, using signed 8-bit binary arithmetic, B - A /// > Having first received a packet with sequence number A,
/// > is less than or equal to 0, but greater than -20, /// > a second packet with sequence number B arrives.
/// > then the packet containing sequence number B shall be deemed out of /// > If, using signed 8-bit binary arithmetic, B - A
/// > sequence and discarded. /// > is less than or equal to 0, but greater than -20,
auto a = sync_sequence_; /// > then the packet containing sequence number B shall be deemed out of
auto b = sequence_number; /// > sequence and discarded.
int8_t dif = b - a; auto a = sync_sequence_;
auto b = sequence_number;
dif = b - a;
}
if (dif <= 0 && dif > -20) if (dif <= 0 && dif > -20)
return; return;
{ {
std::unique_lock lk_wctl(lk_ctl); std::unique_lock lk_ctl(mtx_control);
sync_sequence_ = sequence_number; sync_sequence_ = sequence_number;
} }
DMX::Universe::setData(*sync_data_); DMX::Universe::setData(*sync_data_);