From c90d4632599270326b394f71942cc452b6678bc7 Mon Sep 17 00:00:00 2001 From: khizmax Date: Sun, 24 May 2015 11:12:45 +0300 Subject: [PATCH] Renamed get_result typedef to raw_ptr Doc fixed --- cds/container/lazy_kvlist_rcu.h | 2 +- cds/container/lazy_list_rcu.h | 2 +- cds/container/michael_kvlist_rcu.h | 4 +- cds/container/michael_list_rcu.h | 4 +- cds/container/michael_map_rcu.h | 8 +-- cds/container/michael_set_rcu.h | 8 +-- cds/intrusive/lazy_list_rcu.h | 2 +- cds/intrusive/michael_list_rcu.h | 2 - cds/intrusive/michael_set_rcu.h | 12 ++-- cds/intrusive/striped_set/resizing_policy.h | 16 +++++ cds/urcu/raw_ptr.h | 71 ++++++++++----------- change.log | 2 + tests/test-hdr/map/hdr_map.h | 2 +- tests/test-hdr/set/hdr_intrusive_set.h | 2 +- tests/test-hdr/set/hdr_set.h | 2 +- 15 files changed, 77 insertions(+), 62 deletions(-) diff --git a/cds/container/lazy_kvlist_rcu.h b/cds/container/lazy_kvlist_rcu.h index 625a2218..c805ac02 100644 --- a/cds/container/lazy_kvlist_rcu.h +++ b/cds/container/lazy_kvlist_rcu.h @@ -125,7 +125,7 @@ namespace cds { namespace container { cds::urcu::details::conventional_exempt_pair_cast >; /// Type of \p get() member function return value - typedef value_type * get_result; + typedef value_type * raw_ptr; protected: //@cond diff --git a/cds/container/lazy_list_rcu.h b/cds/container/lazy_list_rcu.h index 0441885a..67f9b292 100644 --- a/cds/container/lazy_list_rcu.h +++ b/cds/container/lazy_list_rcu.h @@ -131,7 +131,7 @@ namespace cds { namespace container { public: using exempt_ptr = cds::urcu::exempt_ptr< gc, node_type, value_type, typename maker::intrusive_traits::disposer >; ///< pointer to extracted node /// Type of \p get() member function return value - typedef value_type * get_result; + typedef value_type * raw_ptr; private: //@cond diff --git a/cds/container/michael_kvlist_rcu.h b/cds/container/michael_kvlist_rcu.h index 5dc7a07c..6c4f61b8 100644 --- a/cds/container/michael_kvlist_rcu.h +++ b/cds/container/michael_kvlist_rcu.h @@ -132,6 +132,7 @@ namespace cds { namespace container { >; private: + //@cond struct raw_ptr_converter { value_type * operator()( node_type * p ) const @@ -149,12 +150,11 @@ namespace cds { namespace container { return n.m_Data; } }; + //@endcond public: /// Result of \p get(), \p get_with() functions - pointer to the node found typedef cds::urcu::raw_ptr_adaptor< value_type, typename base_class::raw_ptr, raw_ptr_converter > raw_ptr; - /// Type of \p get() member function return value - typedef raw_ptr get_result; protected: //@cond diff --git a/cds/container/michael_list_rcu.h b/cds/container/michael_list_rcu.h index 76864658..31baa2ee 100644 --- a/cds/container/michael_list_rcu.h +++ b/cds/container/michael_list_rcu.h @@ -139,6 +139,7 @@ namespace cds { namespace container { using exempt_ptr = cds::urcu::exempt_ptr< gc, node_type, value_type, typename maker::intrusive_traits::disposer >; ///< pointer to extracted node private: + //@cond struct raw_ptr_converter { value_type * operator()( node_type * p ) const @@ -156,12 +157,11 @@ namespace cds { namespace container { return n.m_Value; } }; + //@endcond public: /// Result of \p get(), \p get_with() functions - pointer to the node found typedef cds::urcu::raw_ptr_adaptor< value_type, typename base_class::raw_ptr, raw_ptr_converter > raw_ptr; - /// Type of \p get() member function return value - typedef raw_ptr get_result; private: //@cond diff --git a/cds/container/michael_map_rcu.h b/cds/container/michael_map_rcu.h index 4225aa39..8bbb2208 100644 --- a/cds/container/michael_map_rcu.h +++ b/cds/container/michael_map_rcu.h @@ -75,7 +75,7 @@ namespace cds { namespace container { /// Group of \p extract_xxx functions require external locking if underlying ordered list requires that static CDS_CONSTEXPR const bool c_bExtractLockExternal = bucket_type::c_bExtractLockExternal; /// Type of \p get() member function return value - typedef typename bucket_type::get_result get_result; + typedef typename bucket_type::raw_ptr raw_ptr; //@cond typedef cds::container::michael_map::implementation_tag implementation_tag; @@ -676,7 +676,7 @@ namespace cds { namespace container { typedef cds::container::MichaelHashMap< your_template_parameters > hash_map; hash_map theMap; // ... - typename hash_map::get_result gp; + typename hash_map::raw_ptr gp; { // Lock RCU hash_map::rcu_lock lock; @@ -692,7 +692,7 @@ namespace cds { namespace container { \endcode */ template - get_result get( K const& key ) + raw_ptr get( K const& key ) { return bucket( key ).get( key ); } @@ -707,7 +707,7 @@ namespace cds { namespace container { \p pred must imply the same element order as the comparator used for building the map. */ template - get_result get_with( K const& key, Less pred ) + raw_ptr get_with( K const& key, Less pred ) { return bucket( key ).get_with( key, pred ); } diff --git a/cds/container/michael_set_rcu.h b/cds/container/michael_set_rcu.h index 02761999..501d4393 100644 --- a/cds/container/michael_set_rcu.h +++ b/cds/container/michael_set_rcu.h @@ -123,7 +123,7 @@ namespace cds { namespace container { typedef typename bucket_type::rcu_lock rcu_lock; ///< RCU scoped lock typedef typename bucket_type::exempt_ptr exempt_ptr; ///< pointer to extracted node - typedef typename bucket_type::get_result get_result; ///< Return type of \p get() member function and its derivatives + typedef typename bucket_type::raw_ptr raw_ptr; ///< Return type of \p get() member function and its derivatives /// Group of \p extract_xxx functions require external locking if underlying ordered list requires that static CDS_CONSTEXPR const bool c_bExtractLockExternal = bucket_type::c_bExtractLockExternal; @@ -617,7 +617,7 @@ namespace cds { namespace container { \code typedef cds::container::MichaelHashSet< your_template_parameters > hash_set; hash_set theSet; - typename hash_set::get_result gp; + typename hash_set::raw_ptr gp; // ... { // Lock RCU @@ -634,7 +634,7 @@ namespace cds { namespace container { \endcode */ template - get_result get( Q const& key ) + raw_ptr get( Q const& key ) { return bucket( key ).get( key ); } @@ -649,7 +649,7 @@ namespace cds { namespace container { \p pred must imply the same element order as the comparator used for building the set. */ template - get_result get_with( Q const& key, Less pred ) + raw_ptr get_with( Q const& key, Less pred ) { return bucket( key ).get_with( key, pred ); } diff --git a/cds/intrusive/lazy_list_rcu.h b/cds/intrusive/lazy_list_rcu.h index bb9655d0..908659a3 100644 --- a/cds/intrusive/lazy_list_rcu.h +++ b/cds/intrusive/lazy_list_rcu.h @@ -233,7 +233,7 @@ namespace cds { namespace intrusive { /// pointer to extracted node using exempt_ptr = cds::urcu::exempt_ptr< gc, value_type, value_type, clear_and_dispose, void >; /// Type of \p get() member function return value - typedef value_type * get_result; + typedef value_type * raw_ptr; protected: //@cond diff --git a/cds/intrusive/michael_list_rcu.h b/cds/intrusive/michael_list_rcu.h index 000a1b8d..5843367d 100644 --- a/cds/intrusive/michael_list_rcu.h +++ b/cds/intrusive/michael_list_rcu.h @@ -236,8 +236,6 @@ namespace cds { namespace intrusive { public: /// Result of \p get(), \p get_with() functions - pointer to the node found typedef cds::urcu::raw_ptr< gc, value_type, raw_ptr_disposer > raw_ptr; - /// Type of \p get() member function return value - typedef raw_ptr get_result; protected: //@cond diff --git a/cds/intrusive/michael_set_rcu.h b/cds/intrusive/michael_set_rcu.h index 5aff39dd..a93e0fe3 100644 --- a/cds/intrusive/michael_set_rcu.h +++ b/cds/intrusive/michael_set_rcu.h @@ -89,9 +89,9 @@ namespace cds { namespace intrusive { /// Bucket table allocator typedef cds::details::Allocator< bucket_type, typename traits::allocator > bucket_table_allocator; - typedef typename bucket_type::rcu_lock rcu_lock; ///< RCU scoped lock - typedef typename bucket_type::exempt_ptr exempt_ptr; ///< pointer to extracted node - typedef typename bucket_type::get_result get_result; ///< Return type of \p get() member function and its derivatives + typedef typename bucket_type::rcu_lock rcu_lock; ///< RCU scoped lock + typedef typename bucket_type::exempt_ptr exempt_ptr; ///< pointer to extracted node + typedef typename bucket_type::raw_ptr raw_ptr; ///< Return type of \p get() member function and its derivatives /// Group of \p extract_xxx functions require external locking if underlying ordered list requires that static CDS_CONSTEXPR const bool c_bExtractLockExternal = bucket_type::c_bExtractLockExternal; @@ -557,7 +557,7 @@ namespace cds { namespace intrusive { hash_set theSet; // ... // Result of get() call - typename hash_set::get_result ptr; + typename hash_set::raw_ptr ptr; { // Lock RCU hash_set::rcu_lock lock; @@ -573,7 +573,7 @@ namespace cds { namespace intrusive { \endcode */ template - get_result get( Q const& key ) + raw_ptr get( Q const& key ) { return bucket( key ).get( key ); } @@ -588,7 +588,7 @@ namespace cds { namespace intrusive { \p pred must imply the same element order as the comparator used for building the set. */ template - get_result get_with( Q const& key, Less pred ) + raw_ptr get_with( Q const& key, Less pred ) { return bucket( key ).get_with( key, pred ); } diff --git a/cds/intrusive/striped_set/resizing_policy.h b/cds/intrusive/striped_set/resizing_policy.h index 43cb3f3c..654a8e70 100644 --- a/cds/intrusive/striped_set/resizing_policy.h +++ b/cds/intrusive/striped_set/resizing_policy.h @@ -84,6 +84,14 @@ namespace cds { namespace intrusive { namespace striped_set { {} }; + /// Rational load factor resizing policy + /** @ingroup cds_striped_resizing_policy + When total item count in a container exceeds + container.bucket_count() * Numerator / Denominator + then resizing is needed. + + This policy is stateless: \p Numerator and \p Denominator specifies in compile time as template arguments + */ template struct rational_load_factor_resizing { @@ -105,6 +113,14 @@ namespace cds { namespace intrusive { namespace striped_set { {} }; + /// Rational load factor resizing policy + /** @ingroup cds_striped_resizing_policy + When total item count in a container exceeds + container.bucket_count() * Numerator / Denominator + then resizing is needed. + + This policy is stateful: \p Numerator and \p Denominator specifies in construction time. + */ template struct rational_load_factor_resizing<0, Denominator> { diff --git a/cds/urcu/raw_ptr.h b/cds/urcu/raw_ptr.h index c4d0f1c1..58c16646 100644 --- a/cds/urcu/raw_ptr.h +++ b/cds/urcu/raw_ptr.h @@ -30,26 +30,26 @@ namespace cds { namespace urcu { Template arguments: - \p RCU - one of \ref cds_urcu_gc "RCU type" - \p ValueType - type of values stored in container - - \p ReclaimedEnumerator - implemntation-defined for each type of container + - \p ReclaimedEnumerator - implementation-defined for each type of container Example: let \p Container is an RCU container - \code - Container c; - // ... - // Find a key - typename Container::raw_ptr pRaw; - - // RCU locked section - { - typename Container::rcu_lock l; - pRaw = c.get( key ); - if ( pRaw ) { - // Deal with pRaw + @code + Container c; + // ... + // Find a key + typename Container::raw_ptr pRaw; + + // RCU locked section + { + typename Container::rcu_lock l; + pRaw = c.get( key ); + if ( pRaw ) { + // Deal with pRaw + } } - } - // Release outside RCU-lock - pRaw.release(); - \endcode + // Release outside RCU-lock + pRaw.release(); + @endcode */ template < class RCU, @@ -60,7 +60,7 @@ namespace cds { namespace urcu { { public: typedef RCU rcu; ///< RCU type - one of cds::urcu::gc< ... > - typedef ValueType value_type; ///< Value type pointed by \p raw_ptr + typedef ValueType value_type; ///< Value type pointed by \p %raw_ptr typedef ReclaimedEnumerator reclaimed_enumerator; ///< implementation-defined, for internal use only private: @@ -86,7 +86,7 @@ namespace cds { namespace urcu { /// Copy ctor is prohibited raw_ptr( raw_ptr const& ) = delete; - ///@cond + //@cond // Only for internal use raw_ptr( value_type * p, reclaimed_enumerator&& e ) : m_ptr( p ) @@ -170,7 +170,7 @@ namespace cds { namespace urcu { }; //@cond - /// Adapter \p raw_ptr for non-intrusive containers based on intrusive counterpart + // Adapter of \p raw_ptr for non-intrusive containers based on intrusive counterpart template < typename ValueType, typename RawPtr, @@ -185,33 +185,33 @@ namespace cds { namespace urcu { typedef Converter converter_type; public: - /// Constructs an empty raw pointer + // Constructs an empty raw pointer raw_ptr_adaptor() : intrusive_raw_ptr() {} - /// Move ctor + // Move ctor raw_ptr_adaptor( intrusive_raw_ptr&& p ) : intrusive_raw_ptr( std::move(p)) {} - /// Move ctor + // Move ctor raw_ptr_adaptor( raw_ptr_adaptor&& p ) : intrusive_raw_ptr( std::move(p)) {} - /// Copy ctor is prohibited + // Copy ctor is prohibited raw_ptr_adaptor( raw_ptr_adaptor const& ) = delete; - /// Releases the raw pointer + // Releases the raw pointer ~raw_ptr_adaptor() { release(); } public: - /// Move assignment operator - /** + // Move assignment operator + /* This operator may be called only inside RCU-lock. The \p this should be empty. @@ -223,41 +223,41 @@ namespace cds { namespace urcu { return *this; } - /// Copy assignment is prohibited + // Copy assignment is prohibited raw_ptr_adaptor& operator=( raw_ptr_adaptor const& ) = delete; - /// Returns a pointer to stored value + // Returns a pointer to stored value value_type * operator ->() const CDS_NOEXCEPT { return converter_type()( intrusive_raw_ptr::operator->()); } - /// Returns a reference to stored value + // Returns a reference to stored value value_type& operator *() { return converter_type()( intrusive_raw_ptr::operator*()); } - /// Returns a reference to stored value + // Returns a reference to stored value value_type const& operator *() const { return converter_type()( intrusive_raw_ptr::operator*()); } - /// Checks if the \p %raw_ptr is \p nullptr + // Checks if the \p %raw_ptr is \p nullptr bool empty() const CDS_NOEXCEPT { return intrusive_raw_ptr::empty(); } - /// Checks if the \p %raw_ptr is not empty + // Checks if the \p %raw_ptr is not empty explicit operator bool() const CDS_NOEXCEPT { return !empty(); } - /// Releases the \p %raw_ptr object - /** + // Releases the \p %raw_ptr object + /* This function may be called only outside RCU section. After \p %release() the object can be reused. */ @@ -271,4 +271,3 @@ namespace cds { namespace urcu { }} // namespace cds::urcu #endif // #ifndef CDSLIB_URCU_RAW_PTR_H - diff --git a/change.log b/change.log index 8009c305..7960a2d2 100644 --- a/change.log +++ b/change.log @@ -6,6 +6,8 @@ variants for MichaelList RCU-based specialization: extract() does not require RCU locking, get() now returns special wrapper object of type raw_ptr, see doc. + Thus, semantics of extract()/get() of all RCU-based set and maps based on + MichaelList (MichaelSet/Map, SplitListSet/Map) has been changed too. - cds::lock namespace is renamed to cds::sync. All classes defined in cds::lock namespace are moved to cds::sync with new names (for example, cds::lock::SpinLock is renamed to cds::sync::spin_lock). cds::lock namespace and its contents is deprecated, it is kept diff --git a/tests/test-hdr/map/hdr_map.h b/tests/test-hdr/map/hdr_map.h index d8986ee2..fc6872ae 100644 --- a/tests/test-hdr/map/hdr_map.h +++ b/tests/test-hdr/map/hdr_map.h @@ -357,7 +357,7 @@ namespace map { typedef typename Map::rcu_lock rcu_lock; typedef typename Map::value_type value_type; typename Map::exempt_ptr ep; - typename Map::get_result gp; + typename Map::raw_ptr gp; static size_t const nLimit = 100; int arr[nLimit]; diff --git a/tests/test-hdr/set/hdr_intrusive_set.h b/tests/test-hdr/set/hdr_intrusive_set.h index 199551c9..861d1fe1 100644 --- a/tests/test-hdr/set/hdr_intrusive_set.h +++ b/tests/test-hdr/set/hdr_intrusive_set.h @@ -1107,7 +1107,7 @@ namespace set { typedef typename Set::rcu_lock rcu_lock; typename Set::exempt_ptr ep; - typename Set::get_result gp; + typename Set::raw_ptr gp; { static size_t const nLimit = 1024; diff --git a/tests/test-hdr/set/hdr_set.h b/tests/test-hdr/set/hdr_set.h index 47d07ec4..2d23869b 100644 --- a/tests/test-hdr/set/hdr_set.h +++ b/tests/test-hdr/set/hdr_set.h @@ -506,7 +506,7 @@ namespace set { typedef typename Set::rcu_lock rcu_lock; typedef typename Set::value_type value_type; typename Set::exempt_ptr ep; - typename Set::get_result gp; + typename Set::raw_ptr gp; static size_t const nLimit = 100; int arr[nLimit]; -- 2.34.1