1
0
Fork 0

don't hold the control lock when doing callbacks

This commit is contained in:
Kevin Matz 2022-12-10 13:34:45 -05:00
parent 99e42dba17
commit 293b2060b8
2 changed files with 2 additions and 11 deletions

View File

@ -295,7 +295,6 @@ void Universe::rx_timeout_(bool add_now)
*/
void Universe::do_callbacks_(std::vector<std::weak_ptr<const std::function<void(Universe*)>>> & callbacks)
{
std::shared_lock lk_ctl(mtx_control);
for (auto it = callbacks.cbegin(); it != callbacks.cend();)
{
if (auto sp = it->lock())
@ -305,11 +304,8 @@ void Universe::do_callbacks_(std::vector<std::weak_ptr<const std::function<void(
}
else
{ // the owner has released the token
lk_ctl.unlock(); // release the shared lock
mtx_control.lock(); // take a unique lock
std::unique_lock lk(mtx_control);
it = callbacks.erase(it);
mtx_control.unlock(); // release the unique lock
lk_ctl.lock(); // retake the shared lock
}
}
}

View File

@ -192,7 +192,6 @@ std::shared_ptr<void> ArbitratingUniverse::onSourceListChange(std::function<void
*/
void ArbitratingUniverse::doListChangeCallbacks()
{
std::shared_lock lk_ctl(mtx_control);
for (auto it = cb_sourceListChange.cbegin(); it != cb_sourceListChange.cend();)
{
if (auto sp = it->lock())
@ -202,12 +201,8 @@ void ArbitratingUniverse::doListChangeCallbacks()
}
else
{ // or remove the callback
lk_ctl.unlock(); // release the shared lock
mtx_control.lock(); // take a unique lock
std::unique_lock lk_ctl(mtx_control);
it = cb_sourceListChange.erase(it);
mtx_control.unlock(); // release the unique lock
lk_ctl.lock(); // retake the shared lock
}
}
}