use scoped mutex locking
This commit is contained in:
parent
1f57ef1029
commit
c4cf9768ab
|
@ -59,10 +59,9 @@ void Source::create(const uint16_t num)
|
|||
metadata->source_name = this->name();
|
||||
metadata->universe = num;
|
||||
|
||||
universes_mutext_.lock();
|
||||
std::unique_lock lk(mtx_universes_);
|
||||
universes_.emplace(num, std::make_shared<Universe>(this));
|
||||
universes_[num]->setMetadata(metadata);
|
||||
universes_mutext_.unlock();
|
||||
}
|
||||
|
||||
|
||||
|
@ -75,12 +74,11 @@ void Source::terminate(const uint16_t num)
|
|||
if (!universes_.count(num))
|
||||
return;
|
||||
|
||||
universes_mutext_.lock();
|
||||
std::unique_lock lk(mtx_universes_);
|
||||
auto metadata = universes_.at(num)->metadata();
|
||||
metadata->options.stream_terminated = true;
|
||||
universes_.at(num)->setMetadata(metadata);
|
||||
universes_.erase(num);
|
||||
universes_mutext_.unlock();
|
||||
}
|
||||
|
||||
|
||||
|
@ -115,15 +113,16 @@ void Source::sendExtendedFrame(const uint16_t vector,
|
|||
*/
|
||||
std::shared_ptr<Universe> Source::universe(const uint16_t num)
|
||||
{
|
||||
std::shared_lock lk(mtx_universes_);
|
||||
if (!universes_.count(num))
|
||||
return nullptr;
|
||||
|
||||
return universes_.at(num);
|
||||
}
|
||||
|
||||
|
||||
void Source::assignUserName(const std::string s)
|
||||
{
|
||||
std::shared_lock lk(mtx_universes_);
|
||||
ACN::Component::assignUserName(s);
|
||||
for( auto & [_, universe] : universes_ )
|
||||
universe->metadata()->source_name = name();
|
||||
|
@ -177,19 +176,20 @@ void Source::discovery_send_()
|
|||
|
||||
// known universes
|
||||
std::vector<std::shared_ptr<EXTENDED::DISCOVERY::discoveredUniverse>> list;
|
||||
universes_mutext_.lock();
|
||||
for (const auto & [num, univ] : universes_)
|
||||
{
|
||||
if (!univ->activeSlots())
|
||||
continue;
|
||||
if (univ->metadata()->options.stream_terminated)
|
||||
continue;
|
||||
if (univ->destination.type != ACN::SDT::SDT_ADDR_NULL)
|
||||
continue;
|
||||
list.emplace_back(std::make_shared<EXTENDED::DISCOVERY::discoveredUniverse>());
|
||||
list.back()->universe = num;
|
||||
}
|
||||
universes_mutext_.unlock();
|
||||
{
|
||||
std::shared_lock lk(mtx_universes_);
|
||||
for (const auto & [num, univ] : universes_)
|
||||
{
|
||||
if (!univ->activeSlots())
|
||||
continue;
|
||||
if (univ->metadata()->options.stream_terminated)
|
||||
continue;
|
||||
if (univ->destination.type != ACN::SDT::SDT_ADDR_NULL)
|
||||
continue;
|
||||
list.emplace_back(std::make_shared<EXTENDED::DISCOVERY::discoveredUniverse>());
|
||||
list.back()->universe = num;
|
||||
}
|
||||
}
|
||||
|
||||
/// > \cite sACN 8.3 Page
|
||||
/// >
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "universe.h"
|
||||
|
||||
#include <future>
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
#include <unordered_map>
|
||||
#include <thread>
|
||||
|
||||
|
@ -66,7 +66,7 @@ protected:
|
|||
|
||||
private:
|
||||
std::unordered_map <uint16_t, std::shared_ptr<Universe>> universes_;
|
||||
mutable std::mutex universes_mutext_; //!< thread safety protection for universes_
|
||||
mutable std::shared_mutex mtx_universes_; //!< thread safety protection for universes_
|
||||
|
||||
/// > \cite sACN 12 Universe Discovery
|
||||
/// >
|
||||
|
|
Loading…
Reference in New Issue