Changeset View
Changeset View
Standalone View
Standalone View
src/rwcollection.h
// Copyright (c) 2018-2019 The Bitcoin developers | // Copyright (c) 2018-2019 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_RWCOLLECTION_H | #ifndef BITCOIN_RWCOLLECTION_H | ||||
#define BITCOIN_RWCOLLECTION_H | #define BITCOIN_RWCOLLECTION_H | ||||
#include <threadsafety.h> | |||||
#include <boost/noncopyable.hpp> | #include <boost/noncopyable.hpp> | ||||
#include <boost/range/iterator.hpp> | #include <boost/range/iterator.hpp> | ||||
#include <boost/thread/locks.hpp> | #include <boost/thread/locks.hpp> | ||||
#include <boost/thread/shared_mutex.hpp> | #include <boost/thread/shared_mutex.hpp> | ||||
#include <iterator> | #include <iterator> | ||||
#include <type_traits> | #include <type_traits> | ||||
#include <utility> | #include <utility> | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | public: | ||||
*/ | */ | ||||
template <typename I> typename BracketType<I>::type operator[](I &&index) { | template <typename I> typename BracketType<I>::type operator[](I &&index) { | ||||
return (*collection)[std::forward<I>(index)]; | return (*collection)[std::forward<I>(index)]; | ||||
} | } | ||||
}; | }; | ||||
template <typename T> class RWCollection { | template <typename T> class RWCollection { | ||||
private: | private: | ||||
T collection GUARDED_BY(rwlock); | |||||
mutable boost::shared_mutex rwlock; | mutable boost::shared_mutex rwlock; | ||||
T collection; | |||||
public: | public: | ||||
RWCollection() : collection() {} | RWCollection() : collection() {} | ||||
typedef RWCollectionView<const T, boost::shared_lock<boost::shared_mutex>> | typedef RWCollectionView<const T, boost::shared_lock<boost::shared_mutex>> | ||||
ReadView; | ReadView; | ||||
ReadView getReadView() const { | ReadView getReadView() const { | ||||
return ReadView(boost::shared_lock<boost::shared_mutex>(rwlock), | return ReadView(boost::shared_lock<boost::shared_mutex>(rwlock), | ||||
Show All 12 Lines |