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,10 +95,11 @@ 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;
{
std::shared_lock lk_ctl(mtx_control);
/// > \cite sACN 6.7.2 Sequence Numbering /// > \cite sACN 6.7.2 Sequence Numbering
/// > /// >
/// > Having first received a packet with sequence number A, /// > Having first received a packet with sequence number A,
@ -109,11 +110,12 @@ void Universe::synchronize(uint8_t sequence_number)
/// > sequence and discarded. /// > sequence and discarded.
auto a = sync_sequence_; auto a = sync_sequence_;
auto b = sequence_number; auto b = sequence_number;
int8_t dif = b - a; 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_);