From eb47f6543f152fd0aaff7106780468f76ea5e04b Mon Sep 17 00:00:00 2001 From: Kevin Matz Date: Fri, 9 Dec 2022 23:09:52 -0500 Subject: [PATCH] correct locking semantics --- protocol/esta/sacn/arbitratinguniverse.cpp | 7 ++--- protocol/esta/sacn/universe.cpp | 30 ++++++++++++---------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/protocol/esta/sacn/arbitratinguniverse.cpp b/protocol/esta/sacn/arbitratinguniverse.cpp index 5a3d56a..8ba79ab 100644 --- a/protocol/esta/sacn/arbitratinguniverse.cpp +++ b/protocol/esta/sacn/arbitratinguniverse.cpp @@ -139,7 +139,9 @@ void ArbitratingUniverse::deleteSourceUniverse(const DATA::data_header& src) return; if (sources_.size() == 1 && hold_last_look_) return; - std::unique_lock lk_wctl(lk_ctl); + } + { + std::unique_lock lk_ctl(mtx_control); sources_.erase(src); } doListChangeCallbacks(); @@ -187,7 +189,6 @@ std::shared_ptr ArbitratingUniverse::onSourceListChange(std::functionlock()) @@ -197,7 +198,7 @@ void ArbitratingUniverse::doListChangeCallbacks() } else { // or remove the callback - std::unique_lock lk_wctl(lk_ctl); + std::unique_lock lk_ctl(mtx_control); it = cb_sourceListChange.erase(it); } } diff --git a/protocol/esta/sacn/universe.cpp b/protocol/esta/sacn/universe.cpp index b28a929..f688ec0 100644 --- a/protocol/esta/sacn/universe.cpp +++ b/protocol/esta/sacn/universe.cpp @@ -95,25 +95,27 @@ bool Universe::isSyncronized() */ void Universe::synchronize(uint8_t sequence_number) { - std::shared_lock lk_ctl(mtx_control); if (!sync_data_) return; - - /// > \cite sACN 6.7.2 Sequence Numbering - /// > - /// > Having first received a packet with sequence number A, - /// > a second packet with sequence number B arrives. - /// > If, using signed 8-bit binary arithmetic, B - A - /// > is less than or equal to 0, but greater than -20, - /// > then the packet containing sequence number B shall be deemed out of - /// > sequence and discarded. - auto a = sync_sequence_; - auto b = sequence_number; - int8_t dif = b - a; + int8_t dif; + { + std::shared_lock lk_ctl(mtx_control); + /// > \cite sACN 6.7.2 Sequence Numbering + /// > + /// > Having first received a packet with sequence number A, + /// > a second packet with sequence number B arrives. + /// > If, using signed 8-bit binary arithmetic, B - A + /// > is less than or equal to 0, but greater than -20, + /// > then the packet containing sequence number B shall be deemed out of + /// > sequence and discarded. + auto a = sync_sequence_; + auto b = sequence_number; + dif = b - a; + } if (dif <= 0 && dif > -20) return; { - std::unique_lock lk_wctl(lk_ctl); + std::unique_lock lk_ctl(mtx_control); sync_sequence_ = sequence_number; } DMX::Universe::setData(*sync_data_);