diff options
author | Alexander Batischev <eual.jp@gmail.com> | 2020-06-23 18:39:54 +0300 |
---|---|---|
committer | Alexander Batischev <eual.jp@gmail.com> | 2020-06-23 18:39:54 +0300 |
commit | dd42cc37d21829df1d2322e2bfe7d7f5170e29ed (patch) | |
tree | af5fc36b97c4a3ec9207d19591c9d33a275207a1 | |
parent | 34294027b3c887e4d491cf2f2ecf42e2fb7ad04e (diff) |
Make FeedContainer methods thread-safe
Fixes #1025.
Thanks to @dennisschagt for investigating that issue to a point where
the problem was rather obvious.
-rw-r--r-- | include/feedcontainer.h | 2 | ||||
-rw-r--r-- | src/feedcontainer.cpp | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/include/feedcontainer.h b/include/feedcontainer.h index 2bf9dad0..082ae4db 100644 --- a/include/feedcontainer.h +++ b/include/feedcontainer.h @@ -43,7 +43,7 @@ public: std::vector<std::shared_ptr<RssFeed>> feeds; private: - std::mutex feeds_mutex; + mutable std::mutex feeds_mutex; }; } // namespace newsboat diff --git a/src/feedcontainer.cpp b/src/feedcontainer.cpp index b794de24..b85165c9 100644 --- a/src/feedcontainer.cpp +++ b/src/feedcontainer.cpp @@ -193,6 +193,7 @@ unsigned int FeedContainer::get_unread_item_count_per_tag( std::shared_ptr<RssFeed> FeedContainer::get_feed_by_url( const std::string& feedurl) { + std::lock_guard<std::mutex> feedslock(feeds_mutex); for (const auto& feed : feeds) { if (feedurl == feed->rssurl()) { return feed; @@ -257,6 +258,7 @@ void FeedContainer::clear_feeds_items() unsigned int FeedContainer::unread_feed_count() const { + std::lock_guard<std::mutex> feedslock(feeds_mutex); return std::count_if(feeds.begin(), feeds.end(), [](const std::shared_ptr<RssFeed> feed) { @@ -266,6 +268,7 @@ unsigned int FeedContainer::unread_feed_count() const unsigned int FeedContainer::unread_item_count() const { + std::lock_guard<std::mutex> feedslock(feeds_mutex); return std::accumulate(feeds.begin(), feeds.end(), 0, |