take the control lock when running callbacks
This commit is contained in:
parent
8ce86353c9
commit
849da8cecb
|
@ -295,6 +295,7 @@ 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())
|
||||
|
@ -304,8 +305,11 @@ void Universe::do_callbacks_(std::vector<std::weak_ptr<const std::function<void(
|
|||
}
|
||||
else
|
||||
{ // the owner has released the token
|
||||
std::unique_lock lk(mtx_control);
|
||||
lk_ctl.unlock(); // release the shared lock
|
||||
mtx_control.lock(); // take a unique lock
|
||||
it = callbacks.erase(it);
|
||||
mtx_control.unlock(); // release the unique lock
|
||||
lk_ctl.lock(); // retake the shared lock
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -183,6 +183,7 @@ 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())
|
||||
|
@ -192,8 +193,12 @@ void ArbitratingUniverse::doListChangeCallbacks()
|
|||
}
|
||||
else
|
||||
{ // or remove the callback
|
||||
std::unique_lock lk_ctl(mtx_control);
|
||||
|
||||
lk_ctl.unlock(); // release the shared lock
|
||||
mtx_control.lock(); // take a unique lock
|
||||
it = cb_sourceListChange.erase(it);
|
||||
mtx_control.unlock(); // release the unique lock
|
||||
lk_ctl.lock(); // retake the shared lock
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue