Skip to content

Commit

Permalink
Replace boost::shared_mutex and shared_lock with their std:: equivale…
Browse files Browse the repository at this point in the history
…nt in rwcollection.h

Summary:
This is possible since we use C++17.

Note that core raised some concerns about std::shared_mutex because of a couple bad glibc bugs that could cause deadlocks (bitcoin/bitcoin#16684 (comment)), so I checked that our release building version (Debian 10) was patched. As far as I can tell all our officially supported Linux are safe (all the ones we provide packages for). The only major distro I don't know for sure is CentOS 8, which runs a patched 2.28 version.

Ref T1634.

Test Plan:
  ninja all check-all
  ./contrib/teamcity/build-configurations.py build-tsan

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Maniphest Tasks: T1634

Differential Revision: https://reviews.bitcoinabc.org/D9877
  • Loading branch information
Fabcien committed Aug 16, 2021
1 parent e0c13cd commit d5746a9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
14 changes: 6 additions & 8 deletions src/rwcollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
#include <threadsafety.h>

#include <boost/range/iterator.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/shared_mutex.hpp>

#include <iterator>
#include <shared_mutex>
#include <type_traits>
#include <utility>

Expand Down Expand Up @@ -67,22 +66,21 @@ template <typename T, typename L> class RWCollectionView {
template <typename T> class RWCollection {
private:
T collection;
mutable boost::shared_mutex rwmutex;
mutable std::shared_mutex rwmutex;

public:
RWCollection() : collection() {}

using ReadView =
RWCollectionView<const T, boost::shared_lock<boost::shared_mutex>>;
RWCollectionView<const T, std::shared_lock<std::shared_mutex>>;
ReadView getReadView() const {
return ReadView(boost::shared_lock<boost::shared_mutex>(rwmutex),
return ReadView(std::shared_lock<std::shared_mutex>(rwmutex),
collection);
}

using WriteView =
RWCollectionView<T, boost::unique_lock<boost::shared_mutex>>;
using WriteView = RWCollectionView<T, std::unique_lock<std::shared_mutex>>;
WriteView getWriteView() {
return WriteView(boost::unique_lock<boost::shared_mutex>(rwmutex),
return WriteView(std::unique_lock<std::shared_mutex>(rwmutex),
collection);
}
};
Expand Down
1 change: 0 additions & 1 deletion test/lint/lint-boost-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ EXPECTED_BOOST_INCLUDES=(
boost/signals2/signal.hpp
boost/test/unit_test.hpp
boost/thread/condition_variable.hpp
boost/thread/locks.hpp
boost/thread/mutex.hpp
boost/thread/shared_mutex.hpp
boost/thread/thread.hpp
Expand Down

0 comments on commit d5746a9

Please sign in to comment.