diff --git a/src/rwcollection.h b/src/rwcollection.h index f1f600da1..e17ad3e6b 100644 --- a/src/rwcollection.h +++ b/src/rwcollection.h @@ -1,88 +1,88 @@ // Copyright (c) 2018-2019 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_RWCOLLECTION_H #define BITCOIN_RWCOLLECTION_H #include #include #include #include #include #include #include #include template class RWCollectionView : boost::noncopyable { private: L lock; T *collection; template struct BracketType { using type = decltype(std::declval()[std::declval()]); }; public: RWCollectionView(L l, T &c) : lock(std::move(l)), collection(&c) {} RWCollectionView(RWCollectionView &&other) : lock(std::move(other.lock)), collection(other.collection) {} T *operator->() { return collection; } const T *operator->() const { return collection; } /** * Iterator mechanics. */ using iterator = typename boost::range_iterator::type; iterator begin() { return std::begin(*collection); } iterator end() { return std::end(*collection); } std::reverse_iterator rbegin() { return std::rbegin(*collection); } std::reverse_iterator rend() { return std::rend(*collection); } using const_iterator = typename boost::range_iterator::type; const_iterator begin() const { return std::begin(*collection); } const_iterator end() const { return std::end(*collection); } std::reverse_iterator rbegin() const { return std::rbegin(*collection); } std::reverse_iterator rend() const { return std::rend(*collection); } /** * Forward bracket operator. */ template typename BracketType::type operator[](I &&index) { return (*collection)[std::forward(index)]; } }; template class RWCollection { private: - T collection GUARDED_BY(rwlock); - mutable boost::shared_mutex rwlock; + T collection; + mutable boost::shared_mutex rwmutex; public: RWCollection() : collection() {} using ReadView = RWCollectionView>; ReadView getReadView() const { - return ReadView(boost::shared_lock(rwlock), + return ReadView(boost::shared_lock(rwmutex), collection); } using WriteView = RWCollectionView>; WriteView getWriteView() { - return WriteView(boost::unique_lock(rwlock), + return WriteView(boost::unique_lock(rwmutex), collection); } }; #endif // BITCOIN_RWCOLLECTION_H