From 4c4f84d86203ea6eb162329796e32a9d0b4441e2 Mon Sep 17 00:00:00 2001 From: khizmax Date: Thu, 9 Oct 2014 11:35:59 +0400 Subject: [PATCH] FCStack refactoring --- cds/container/fcstack.h | 27 ++++++++-------- cds/intrusive/fcstack.h | 31 +++++++++---------- tests/test-hdr/stack/hdr_fcstack.cpp | 10 +++--- .../test-hdr/stack/hdr_intrusive_fcstack.cpp | 21 +++++++------ 4 files changed, 44 insertions(+), 45 deletions(-) diff --git a/cds/container/fcstack.h b/cds/container/fcstack.h index be0130a8..fac698ec 100644 --- a/cds/container/fcstack.h +++ b/cds/container/fcstack.h @@ -47,23 +47,22 @@ namespace cds { namespace container { }; /// FCStack type traits - struct type_traits: public cds::algo::flat_combining::type_traits + struct traits: public cds::algo::flat_combining::type_traits { typedef empty_stat stat; ///< Internal statistics - static CDS_CONSTEXPR_CONST bool enable_elimination = false; ///< Enable \ref cds_elimination_description "elimination" + static CDS_CONSTEXPR const bool enable_elimination = false; ///< Enable \ref cds_elimination_description "elimination" }; /// Metafunction converting option list to traits /** - This is a wrapper for cds::opt::make_options< type_traits, Options...> \p Options are: - \p opt::lock_type - mutex type, default is \p cds::lock::Spin - \p opt::back_off - back-off strategy, defalt is \p cds::backoff::Default - \p opt::allocator - allocator type, default is \ref CDS_DEFAULT_ALLOCATOR - - \p opt::stat - internal statistics, possible type: \ref stat, \ref empty_stat (the default) + - \p opt::stat - internal statistics, possible type: \p fcstack::stat, \p fcstack::empty_stat (the default) - \p opt::memory_model - C++ memory ordering model. - List of all available memory ordering see opt::memory_model. - Default if cds::opt::v:relaxed_ordering + List of all available memory ordering see \p opt::memory_model. + Default is \p cds::opt::v:relaxed_ordering - \p opt::enable_elimination - enable/disable operation \ref cds_elimination_description "elimination" By default, the elimination is disabled. */ @@ -73,7 +72,7 @@ namespace cds { namespace container { typedef implementation_defined type ; ///< Metafunction result # else typedef typename cds::opt::make_options< - typename cds::opt::find_type_traits< type_traits, Options... >::type + typename cds::opt::find_type_traits< traits, Options... >::type ,Options... >::type type; # endif @@ -91,12 +90,12 @@ namespace cds { namespace container { Template parameters: - \p T - a value type stored in the stack - \p Stack - sequential stack implementation, default is \p std::stack - - \p Trats - type traits of flat combining, default is \p fcstack::type_traits - \p fcstack::make_traits metafunction can be used to construct specialized \p %type_traits + - \p Trats - type traits of flat combining, default is \p fcstack::traits + \p fcstack::make_traits metafunction can be used to construct specialized \p %fcstack::traits */ template , - typename Traits = fcstack::type_traits + typename Traits = fcstack::traits > class FCStack #ifndef CDS_DOXYGEN_INVOKED @@ -106,10 +105,10 @@ namespace cds { namespace container { public: typedef T value_type; ///< Value type typedef Stack stack_type; ///< Sequential stack class - typedef Traits type_traits; ///< Stack type traits + typedef Traits traits; ///< Stack traits - typedef typename type_traits::stat stat; ///< Internal statistics type - static CDS_CONSTEXPR_CONST bool c_bEliminationEnabled = type_traits::enable_elimination; ///< \p true if elimination is enabled + typedef typename traits::stat stat; ///< Internal statistics type + static CDS_CONSTEXPR_CONST bool c_bEliminationEnabled = traits::enable_elimination; ///< \p true if elimination is enabled protected: //@cond @@ -133,7 +132,7 @@ namespace cds { namespace container { //@endcond /// Flat combining kernel - typedef cds::algo::flat_combining::kernel< fc_record, type_traits > fc_kernel; + typedef cds::algo::flat_combining::kernel< fc_record, traits > fc_kernel; protected: //@cond diff --git a/cds/intrusive/fcstack.h b/cds/intrusive/fcstack.h index f985ec77..f70ec59f 100644 --- a/cds/intrusive/fcstack.h +++ b/cds/intrusive/fcstack.h @@ -43,26 +43,25 @@ namespace cds { namespace intrusive { }; /// FCStack type traits - struct type_traits: public cds::algo::flat_combining::type_traits + struct traits: public cds::algo::flat_combining::type_traits { typedef cds::intrusive::opt::v::empty_disposer disposer ; ///< Disposer to erase removed elements. Used only in \p FCStack::clear() function typedef empty_stat stat; ///< Internal statistics - static CDS_CONSTEXPR_CONST bool enable_elimination = false; ///< Enable \ref cds_elimination_description "elimination" + static CDS_CONSTEXPR const bool enable_elimination = false; ///< Enable \ref cds_elimination_description "elimination" }; /// Metafunction converting option list to traits /** - This is a wrapper for cds::opt::make_options< type_traits, Options...> \p Options are: - \p opt::lock_type - mutex type, default is \p cds::lock::Spin - \p opt::back_off - back-off strategy, defalt is \p cds::backoff::Default - - \p opt::disposer - the functor used for dispose removed items. Default is opt::intrusive::v::empty_disposer. + - \p opt::disposer - the functor used for dispose removed items. Default is \p opt::intrusive::v::empty_disposer. This option is used only in \p FCStack::clear() function. - \p opt::allocator - allocator type, default is \ref CDS_DEFAULT_ALLOCATOR - - \p opt::stat - internal statistics, possible type: \ref stat, \ref empty_stat (the default) + - \p opt::stat - internal statistics, possible type: \p fcstack::stat, \p fcstack::empty_stat (the default) - \p opt::memory_model - C++ memory ordering model. - List of all available memory ordering see opt::memory_model. - Default if cds::opt::v:relaxed_ordering + List of all available memory ordering see \p opt::memory_model. + Default is \p cds::opt::v:relaxed_ordering - \p opt::enable_elimination - enable/disable operation \ref cds_elimination_description "elimination" By default, the elimination is disabled. */ @@ -72,7 +71,7 @@ namespace cds { namespace intrusive { typedef implementation_defined type ; ///< Metafunction result # else typedef typename cds::opt::make_options< - typename cds::opt::find_type_traits< type_traits, Options... >::type + typename cds::opt::find_type_traits< traits, Options... >::type ,Options... >::type type; # endif @@ -91,12 +90,12 @@ namespace cds { namespace intrusive { - \p T - a value type stored in the stack - \p Container - sequential intrusive container with \p push_front and \p pop_front functions. Possible containers are \p boost::intrusive::slist (the default), \p boost::inrtrusive::list - - \p Traits - type traits of flat combining, default is \p fcstack::type_traits. - \p fcstack::make_traits metafunction can be used to construct specialized \p %type_traits + - \p Traits - type traits of flat combining, default is \p fcstack::traits. + \p fcstack::make_traits metafunction can be used to construct specialized \p %traits */ template - ,typename Traits = fcstack::type_traits + ,typename Traits = fcstack::traits > class FCStack #ifndef CDS_DOXYGEN_INVOKED @@ -106,11 +105,11 @@ namespace cds { namespace intrusive { public: typedef T value_type; ///< Value type typedef Container container_type; ///< Sequential container type - typedef Traits type_traits; ///< Stack type traits + typedef Traits traits; ///< Stack traits - typedef typename type_traits::disposer disposer; ///< The disposer functor. The disposer is used only in \ref clear() function - typedef typename type_traits::stat stat; ///< Internal statistics type - static CDS_CONSTEXPR_CONST bool c_bEliminationEnabled = type_traits::enable_elimination; ///< \p true if elimination is enabled + typedef typename traits::disposer disposer; ///< The disposer functor. The disposer is used only in \ref clear() function + typedef typename traits::stat stat; ///< Internal statistics type + static CDS_CONSTEXPR_CONST bool c_bEliminationEnabled = traits::enable_elimination; ///< \p true if elimination is enabled protected: //@cond @@ -131,7 +130,7 @@ namespace cds { namespace intrusive { //@endcond /// Flat combining kernel - typedef cds::algo::flat_combining::kernel< fc_record, type_traits > fc_kernel; + typedef cds::algo::flat_combining::kernel< fc_record, traits > fc_kernel; protected: //@cond diff --git a/tests/test-hdr/stack/hdr_fcstack.cpp b/tests/test-hdr/stack/hdr_fcstack.cpp index e360d232..48ebe913 100644 --- a/tests/test-hdr/stack/hdr_fcstack.cpp +++ b/tests/test-hdr/stack/hdr_fcstack.cpp @@ -99,11 +99,11 @@ namespace stack { void TestFCStack::FCStack_deque_elimination() { - typedef cds::container::FCStack< unsigned int, std::stack >, - cds::container::fcstack::make_traits< - cds::opt::enable_elimination< true > - >::type - > stack_type; + struct stack_traits : public cds::container::fcstack::traits + { + static CDS_CONSTEXPR const bool enable_elimination = true; + }; + typedef cds::container::FCStack< unsigned int, std::stack >, stack_traits > stack_type; test(); } diff --git a/tests/test-hdr/stack/hdr_intrusive_fcstack.cpp b/tests/test-hdr/stack/hdr_intrusive_fcstack.cpp index c7bc6cd8..48e22f7c 100644 --- a/tests/test-hdr/stack/hdr_intrusive_fcstack.cpp +++ b/tests/test-hdr/stack/hdr_intrusive_fcstack.cpp @@ -144,22 +144,23 @@ namespace stack { void TestIntrusiveFCStack::FCStack_slist_mutex() { typedef base_hook_item< boost::intrusive::slist_base_hook<> > value_type; - typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type >, - cds::intrusive::fcstack::make_traits< - cds::opt::lock_type< std::mutex > - >::type - > stack_type; + struct stack_traits : public cds::intrusive::fcstack::traits + { + typedef std::mutex lock_type; + }; + typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type >, stack_traits > stack_type; test(); } void TestIntrusiveFCStack::FCStack_slist_elimination() { typedef base_hook_item< boost::intrusive::slist_base_hook<> > value_type; - typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type >, - cds::intrusive::fcstack::make_traits< - cds::opt::enable_elimination< true > - >::type - > stack_type; + struct stack_traits : public + cds::intrusive::fcstack::make_traits < + cds::opt::enable_elimination < true > + > ::type + {}; + typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type >, stack_traits > stack_type; test(); } -- 2.34.1