Changeset View
Changeset View
Standalone View
Standalone View
src/rwcollection.h
Show First 20 Lines • Show All 58 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); | T collection; | ||||
mutable boost::shared_mutex rwlock; | mutable boost::shared_mutex rwmutex; | ||||
public: | public: | ||||
RWCollection() : collection() {} | RWCollection() : collection() {} | ||||
using ReadView = | using ReadView = | ||||
RWCollectionView<const T, boost::shared_lock<boost::shared_mutex>>; | RWCollectionView<const T, boost::shared_lock<boost::shared_mutex>>; | ||||
ReadView getReadView() const { | ReadView getReadView() const { | ||||
return ReadView(boost::shared_lock<boost::shared_mutex>(rwlock), | return ReadView(boost::shared_lock<boost::shared_mutex>(rwmutex), | ||||
collection); | collection); | ||||
} | } | ||||
using WriteView = | using WriteView = | ||||
RWCollectionView<T, boost::unique_lock<boost::shared_mutex>>; | RWCollectionView<T, boost::unique_lock<boost::shared_mutex>>; | ||||
WriteView getWriteView() { | WriteView getWriteView() { | ||||
return WriteView(boost::unique_lock<boost::shared_mutex>(rwlock), | return WriteView(boost::unique_lock<boost::shared_mutex>(rwmutex), | ||||
collection); | collection); | ||||
} | } | ||||
}; | }; | ||||
#endif // BITCOIN_RWCOLLECTION_H | #endif // BITCOIN_RWCOLLECTION_H |