From 0a47113db32c216df356de184ab127654042081c Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Wed, 22 Jul 2020 09:28:39 +0300 Subject: [PATCH] Add more locks to feed --- components/streams/src/feed.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/streams/src/feed.cpp b/components/streams/src/feed.cpp index b085072f7..5f0422565 100644 --- a/components/streams/src/feed.cpp +++ b/components/streams/src/feed.cpp @@ -298,6 +298,7 @@ void Feed::select() { std::vector<std::string> Feed::listSources() { std::vector<std::string> sources; + SHARED_LOCK(mtx_, lk); sources.reserve(fsid_lookup_.size()); for (auto& [uri, fsid] : fsid_lookup_) { std::ignore = fsid; @@ -322,9 +323,11 @@ Feed::Filter* Feed::filter(const std::unordered_set<Channel> &channels) { Feed::Filter* Feed::filter(const std::unordered_set<std::string> &sources, const std::unordered_set<Channel> &channels) { std::unordered_set<uint32_t> fsids; + + SHARED_LOCK(mtx_, lk); for (const auto &src : sources) { ftl::URI uri(src); - // FIXME: If this map is modified, this could crash here. + auto i = fsid_lookup_.find(uri.getBaseURI()); if (i != fsid_lookup_.end()) { fsids.emplace(i->second); @@ -479,6 +482,7 @@ void Feed::updateNetSources() { } std::vector<std::string> Feed::availableNetworkSources() { + SHARED_LOCK(mtx_, lk); return netcams_; } @@ -523,6 +527,7 @@ bool Feed::sourceAvailable(const std::string &uri) { bool Feed::sourceActive(const std::string &suri) { ftl::URI uri(suri); + SHARED_LOCK(mtx_, lk); return fsid_lookup_.count(uri.getBaseURI()) > 0; } @@ -737,6 +742,7 @@ const std::unordered_set<Channel> Feed::availableChannels(ftl::data::FrameID id) std::vector<ftl::data::FrameID> Feed::listFrames() { std::vector<ftl::data::FrameID> result; + SHARED_LOCK(mtx_, lk); result.reserve(fsid_lookup_.size()); for (const auto [k, fs] : latest_) { for (unsigned i = 0; i < fs->frames.size(); i++) { @@ -747,6 +753,7 @@ std::vector<ftl::data::FrameID> Feed::listFrames() { } std::string Feed::getURI(uint32_t fsid) { + SHARED_LOCK(mtx_, lk); for (const auto& [k, v] : fsid_lookup_) { if (v == fsid) { return k; @@ -771,6 +778,7 @@ std::string Feed::getSourceURI(ftl::data::FrameID id) { } std::vector<unsigned int> Feed::listFrameSets() { + SHARED_LOCK(mtx_, lk); std::vector<unsigned int> result; result.reserve(fsid_lookup_.size()); for (const auto [k, fs] : latest_) { -- GitLab