Uses different pass count for different parallel queue test cases
[libcds.git] / cds / opt / options.h
index 9fa817c2070602e5977812e0fb03b5858bb70dc8..70faba7178a6c1a36a4630730072d2cc666aeb31 100644 (file)
@@ -1,4 +1,32 @@
-//$$CDS-header$$
+/*
+    This file is a part of libcds - Concurrent Data Structures library
+
+    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
+
+    Source code repo: http://github.com/khizmax/libcds/
+    Download: http://sourceforge.net/projects/libcds/files/
+
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, this
+      list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimer in the documentation
+      and/or other materials provided with the distribution.
+
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
 
 #ifndef CDSLIB_OPT_OPTIONS_H
 #define CDSLIB_OPT_OPTIONS_H
 
 #ifndef CDSLIB_OPT_OPTIONS_H
 #define CDSLIB_OPT_OPTIONS_H
@@ -10,7 +38,7 @@
         2011.01.23 khizmax  Created
 */
 
         2011.01.23 khizmax  Created
 */
 
-#include <stdlib.h> // rand, srand
+#include <cstdlib> // rand, srand
 
 #include <cds/details/aligned_type.h>
 #include <cds/user_setup/allocator.h>
 
 #include <cds/details/aligned_type.h>
 #include <cds/user_setup/allocator.h>
@@ -27,9 +55,6 @@ namespace cds {
 */
 namespace opt {
 
 */
 namespace opt {
 
-    /// Predefined options value (generally, for the options that determine the data types)
-    namespace v {}
-
     /// Type indicates that an option is not specified and the default one should be used
     struct none
     {
     /// Type indicates that an option is not specified and the default one should be used
     struct none
     {
@@ -277,17 +302,18 @@ namespace opt {
         This option allows to set up appropriate item counting policy for that data structure.
 
         Predefined option \p Type:
         This option allows to set up appropriate item counting policy for that data structure.
 
         Predefined option \p Type:
-        - atomicity::empty_item_counter - no item counting performed. It is default policy for many
+        - \p atomicity::empty_item_counter - no item counting performed. It is default policy for many
             containers
             containers
-        - atomicity::item_counter - the class that provides atomically item counting
-        - opt::v::sequential_item_counter - simple non-atomic item counter. This item counter is not intended for
+        - \p atomicity::item_counter - the class that provides atomic item counting
+        - \p atomicity::cache_friendly_item_counter - cache-friendly atomic item counter
+        - \p opt::v::sequential_item_counter - simple non-atomic item counter. This counter is not intended for
             concurrent containers and may be used only if it is explicitly noted.
 
             concurrent containers and may be used only if it is explicitly noted.
 
-        You may provide other implementation of atomicity::item_counter interface for your needs.
+        You may provide other implementation of \p atomicity::item_counter interface for your needs.
 
         Note, the item counting in lock-free containers cannot be exact; for example, if
         item counter for a container returns zero it is not mean that the container is empty.
 
         Note, the item counting in lock-free containers cannot be exact; for example, if
         item counter for a container returns zero it is not mean that the container is empty.
-        Thus, item counter may be used for statistical purposes only.
+        So, the item counter may be used for statistical purposes only.
     */
     template <typename Type>
     struct item_counter {
     */
     template <typename Type>
     struct item_counter {
@@ -299,78 +325,6 @@ namespace opt {
         //@endcond
     };
 
         //@endcond
     };
 
-    namespace v {
-        /// Sequential non-atomic item counter
-        /**
-            This type of item counter is not intended for concurrent containers
-            and may be used only if it is explicitly noted.
-        */
-        class sequential_item_counter
-        {
-        public:
-            typedef size_t counter_type    ;  ///< Counter type
-        protected:
-            counter_type  m_nCounter ;      ///< Counter
-
-        public:
-            sequential_item_counter()
-                : m_nCounter(0)
-            {}
-
-            /// Returns current value of the counter
-            counter_type    value() const
-            {
-                return m_nCounter;
-            }
-
-            /// Same as \ref value() with relaxed memory ordering
-            operator counter_type() const
-            {
-                return value();
-            }
-
-            /// Increments the counter. Semantics: postincrement
-            counter_type inc()
-            {
-                return m_nCounter++;
-            }
-
-            /// Decrements the counter. Semantics: postdecrement
-            counter_type dec()
-            {
-                return m_nCounter--;
-            }
-
-            /// Preincrement
-            counter_type operator ++()
-            {
-                return inc() + 1;
-            }
-            /// Postincrement
-            counter_type operator ++(int)
-            {
-                return inc();
-            }
-
-            /// Predecrement
-            counter_type operator --()
-            {
-                return dec() - 1;
-            }
-            /// Postdecrement
-            counter_type operator --(int)
-            {
-                return dec();
-            }
-
-            /// Resets count to 0
-            void reset()
-            {
-                m_nCounter = 0;
-            }
-        };
-    } // namespace v
-
     /// Special alignment constants for \ref cds::opt::alignment option
     enum special_alignment {
         no_special_alignment = 0,   ///< no special alignment
     /// Special alignment constants for \ref cds::opt::alignment option
     enum special_alignment {
         no_special_alignment = 0,   ///< no special alignment
@@ -417,9 +371,9 @@ namespace opt {
         no_special_padding = 0,   ///< no special padding
         cache_line_padding = 1,   ///< use cache line size defined in cds/user_setup/cache_line.h
 
         no_special_padding = 0,   ///< no special padding
         cache_line_padding = 1,   ///< use cache line size defined in cds/user_setup/cache_line.h
 
-        /// Apply padding only for tiny data of size less than required padding
+        /// Apply padding only for tiny data when data size is less than required padding
         /**
         /**
-            The flag means that if your data size is less than the casheline size, the padding is applyed.
+            The flag means that if your data size is less than the cacheline size, the padding is applyed.
             Otherwise no padding will be applyed.
 
             This flag is applyed for padding value:
             Otherwise no padding will be applyed.
 
             This flag is applyed for padding value:
@@ -451,6 +405,26 @@ namespace opt {
         //@endcond
     };
 
         //@endcond
     };
 
+    //@cond
+    template <unsigned Padding>
+    struct actual_padding
+    {
+        enum { value = Padding & ~padding_flags };
+    };
+
+    template <>
+    struct actual_padding<cache_line_padding>
+    {
+        enum { value = cds::c_nCacheLineSize };
+    };
+
+    template <>
+    struct actual_padding<cache_line_padding| padding_tiny_data_only>
+    {
+        enum { value = cds::c_nCacheLineSize };
+    };
+    //@endcond
+
     //@cond
     namespace details {
         enum padding_vs_datasize {
     //@cond
     namespace details {
         enum padding_vs_datasize {
@@ -583,62 +557,6 @@ namespace opt {
         //@endcond
     };
 
         //@endcond
     };
 
-    namespace v {
-        /// Relaxed memory ordering model
-        /**
-            In this memory model the memory constraints are defined according to C++ Memory Model specification:
-            each constraint is mapped to \p std::memory_order constraints one-to-one
-
-            See \p opt::memory_model for explanations
-        */
-        struct relaxed_ordering {
-            //@cond
-            static const atomics::memory_order memory_order_relaxed    = atomics::memory_order_relaxed;
-            static const atomics::memory_order memory_order_consume    = atomics::memory_order_consume;
-            static const atomics::memory_order memory_order_acquire    = atomics::memory_order_acquire;
-            static const atomics::memory_order memory_order_release    = atomics::memory_order_release;
-            static const atomics::memory_order memory_order_acq_rel    = atomics::memory_order_acq_rel;
-            static const atomics::memory_order memory_order_seq_cst    = atomics::memory_order_seq_cst;
-            //@endcond
-        };
-
-        /// Sequential consistent memory ordering model
-        /**
-            In this memory model any memory constraint is equivalent to \p memory_order_seq_cst.
-
-            See \p opt::memory_model for explanations
-        */
-        struct sequential_consistent {
-            //@cond
-            static const atomics::memory_order memory_order_relaxed    = atomics::memory_order_seq_cst;
-            static const atomics::memory_order memory_order_consume    = atomics::memory_order_seq_cst;
-            static const atomics::memory_order memory_order_acquire    = atomics::memory_order_seq_cst;
-            static const atomics::memory_order memory_order_release    = atomics::memory_order_seq_cst;
-            static const atomics::memory_order memory_order_acq_rel    = atomics::memory_order_seq_cst;
-            static const atomics::memory_order memory_order_seq_cst    = atomics::memory_order_seq_cst;
-            //@endcond
-        };
-
-        //@cond
-        /// Totally relaxed memory ordering model (do not use!)
-        /**
-            In this memory model any memory constraint is equivalent to \p memory_order_relaxed.
-            @warning Do not use this model! It intended for testing purposes only
-            to verify debugging instruments like Thread Sanitizer.
-
-            See \p opt::memory_model for explanations
-        */
-        struct total_relaxed_ordering {
-            static const atomics::memory_order memory_order_relaxed    = atomics::memory_order_relaxed;
-            static const atomics::memory_order memory_order_consume    = atomics::memory_order_relaxed;
-            static const atomics::memory_order memory_order_acquire    = atomics::memory_order_relaxed;
-            static const atomics::memory_order memory_order_release    = atomics::memory_order_relaxed;
-            static const atomics::memory_order memory_order_acq_rel    = atomics::memory_order_relaxed;
-            static const atomics::memory_order memory_order_seq_cst    = atomics::memory_order_relaxed;
-        };
-        //@endcond
-    } // namespace v
-
     /// [type-option] Base type traits option setter
     /**
         This option setter is intended generally for internal use for type rebinding.
     /// [type-option] Base type traits option setter
     /**
         This option setter is intended generally for internal use for type rebinding.
@@ -711,22 +629,6 @@ namespace opt {
         //@endcond
     };
 
         //@endcond
     };
 
-    namespace v {
-
-        /// Default swap policy (see opt::swap_policy option)
-        /**
-            The default swap policy is wrappr around \p std::swap algorithm.
-        */
-        struct default_swap_policy {
-            /// Performs swapping of \p v1 and \p v2 using \p std::swap algo
-            template <typename T>
-            void operator()( T& v1, T& v2 ) const
-            {
-                std::swap( v1, v2 );
-            }
-        };
-    } // namespace v
-
     /// Move policy option
     /**
         The move policy specifies an algorithm for moving object content.
     /// Move policy option
     /**
         The move policy specifies an algorithm for moving object content.
@@ -755,19 +657,6 @@ namespace opt {
         //@endcond
     };
 
         //@endcond
     };
 
-    namespace v {
-        /// \ref opt::move_policy "Move policy" based on assignment operator
-        struct assignment_move_policy
-        {
-            /// <tt> dest = src </tt>
-            template <typename T>
-            void operator()( T& dest, T const& src ) const
-            {
-                dest = src;
-            }
-        };
-    } // namespace v
-
     /// [value-option] Enable sorting
     /**
         This option enables (<tt>Enable = true</tt>) or disables (<tt>Enable == false</tt>)
     /// [value-option] Enable sorting
     /**
         This option enables (<tt>Enable = true</tt>) or disables (<tt>Enable == false</tt>)
@@ -807,7 +696,7 @@ namespace opt {
         \p Random can be any STL random number generator producing
         unsigned integer: \p std::linear_congruential_engine,
         \p std::mersenne_twister_engine, \p std::subtract_with_carry_engine
         \p Random can be any STL random number generator producing
         unsigned integer: \p std::linear_congruential_engine,
         \p std::mersenne_twister_engine, \p std::subtract_with_carry_engine
-        and so on, or opt::v::c_rand.
+        and so on, or \p opt::v::c_rand.
 
     */
     template <typename Random>
 
     */
     template <typename Random>
@@ -820,27 +709,19 @@ namespace opt {
         //@endcond
     };
 
         //@endcond
     };
 
-    namespace v {
-        /// \p rand() -base random number generator
-        /**
-            This generator returns a pseudorandom integer in the range 0 to \p RAND_MAX (32767).
-        */
-        struct c_rand {
-            typedef unsigned int result_type; ///< Result type
-
-            /// Constructor initializes object calling \p srand()
-            c_rand()
-            {
-                srand(1);
-            }
-
-            /// Returns next random number calling \p rand()
-            result_type operator()()
-            {
-                return (result_type) rand();
-            }
+    /// [type-option] Free-list implementation
+    /**
+        See \p cds::intrusive::FreeList for free-list interface
+    */
+    template <typename FreeList>
+    struct free_list {
+        //@cond
+        template <typename Base> struct pack: public Base
+        {
+            typedef FreeList free_list;
         };
         };
-    } // namespace v
+        //@endcond
+    };
 
     //@cond
     // For internal use
 
     //@cond
     // For internal use
@@ -865,6 +746,180 @@ namespace opt {
 }}  // namespace cds::opt
 
 
 }}  // namespace cds::opt
 
 
+// ****************************************************
+// Options predefined types and values
+
+namespace cds { namespace opt {
+
+    /// Predefined options value
+    namespace v {
+
+        /// Sequential non-atomic item counter
+        /**
+            This type of \p opt::item_counter option is not intended for concurrent containers
+            and may be used only if it is explicitly noted.
+        */
+        class sequential_item_counter
+        {
+        public:
+            typedef size_t counter_type    ;  ///< Counter type
+        protected:
+            counter_type  m_nCounter ;      ///< Counter
+
+        public:
+            sequential_item_counter()
+                : m_nCounter(0)
+            {}
+
+            /// Returns current value of the counter
+            counter_type    value() const
+            {
+                return m_nCounter;
+            }
+
+            /// Same as \ref value() with relaxed memory ordering
+            operator counter_type() const
+            {
+                return value();
+            }
+
+            /// Increments the counter. Semantics: postincrement
+            counter_type inc()
+            {
+                return m_nCounter++;
+            }
+
+            /// Decrements the counter. Semantics: postdecrement
+            counter_type dec()
+            {
+                return m_nCounter--;
+            }
+
+            /// Preincrement
+            counter_type operator ++()
+            {
+                return inc() + 1;
+            }
+            /// Postincrement
+            counter_type operator ++(int)
+            {
+                return inc();
+            }
+
+            /// Predecrement
+            counter_type operator --()
+            {
+                return dec() - 1;
+            }
+            /// Postdecrement
+            counter_type operator --(int)
+            {
+                return dec();
+            }
+
+            /// Resets count to 0
+            void reset()
+            {
+                m_nCounter = 0;
+            }
+        };
+
+        /// Relaxed memory ordering \p opt::memory_model
+        /**
+            In this ordering the memory constraints are defined according to C++ Memory Model specification:
+            each constraint is mapped to \p std::memory_order constraints one-to-one
+        */
+        struct relaxed_ordering {
+            //@cond
+            static const atomics::memory_order memory_order_relaxed    = atomics::memory_order_relaxed;
+            static const atomics::memory_order memory_order_consume    = atomics::memory_order_consume;
+            static const atomics::memory_order memory_order_acquire    = atomics::memory_order_acquire;
+            static const atomics::memory_order memory_order_release    = atomics::memory_order_release;
+            static const atomics::memory_order memory_order_acq_rel    = atomics::memory_order_acq_rel;
+            static const atomics::memory_order memory_order_seq_cst    = atomics::memory_order_seq_cst;
+            //@endcond
+        };
+
+        /// Sequential consistent \p opt::memory_memory ordering
+        /**
+            In this memory model any memory constraint is equivalent to \p std::memory_order_seq_cst.
+        */
+        struct sequential_consistent {
+            //@cond
+            static const atomics::memory_order memory_order_relaxed    = atomics::memory_order_seq_cst;
+            static const atomics::memory_order memory_order_consume    = atomics::memory_order_seq_cst;
+            static const atomics::memory_order memory_order_acquire    = atomics::memory_order_seq_cst;
+            static const atomics::memory_order memory_order_release    = atomics::memory_order_seq_cst;
+            static const atomics::memory_order memory_order_acq_rel    = atomics::memory_order_seq_cst;
+            static const atomics::memory_order memory_order_seq_cst    = atomics::memory_order_seq_cst;
+            //@endcond
+        };
+
+        //@cond
+        /// Totally relaxed \p opt::memory_model ordering (do not use!)
+        /**
+            In this memory model any memory constraint is equivalent to \p std::memory_order_relaxed.
+            @warning Do not use this model! It intended for testing purposes only
+            to verify debugging instruments like Thread Sanitizer.
+        */
+        struct total_relaxed_ordering {
+            static const atomics::memory_order memory_order_relaxed    = atomics::memory_order_relaxed;
+            static const atomics::memory_order memory_order_consume    = atomics::memory_order_relaxed;
+            static const atomics::memory_order memory_order_acquire    = atomics::memory_order_relaxed;
+            static const atomics::memory_order memory_order_release    = atomics::memory_order_relaxed;
+            static const atomics::memory_order memory_order_acq_rel    = atomics::memory_order_relaxed;
+            static const atomics::memory_order memory_order_seq_cst    = atomics::memory_order_relaxed;
+        };
+        //@endcond
+
+
+        /// Default swap policy for \p opt::swap_policy option
+        /**
+            The default swap policy is wrappr around \p std::swap algorithm.
+        */
+        struct default_swap_policy {
+            /// Performs swapping of \p v1 and \p v2 using \p std::swap algo
+            template <typename T>
+            void operator()( T& v1, T& v2 ) const
+            {
+                std::swap( v1, v2 );
+            }
+        };
+
+        /// \p opt::move_policy based on move-assignment operator
+        struct assignment_move_policy
+        {
+            /// <tt> dest = std::move( src ) </tt>
+            template <typename T>
+            void operator()( T& dest, T&& src ) const
+            {
+                dest = std::move( src );
+            }
+        };
+
+        /// \p rand() -base random number generator for \p opt::random_engine
+        /**
+            This generator returns a pseudorandom integer in the range 0 to \p RAND_MAX (32767).
+        */
+        struct c_rand {
+            typedef unsigned int result_type; ///< Result type
+
+            /// Constructor initializes object calling \p std::srand()
+            c_rand()
+            {
+                std::srand(1);
+            }
+
+            /// Returns next random number calling \p std::rand()
+            result_type operator()()
+            {
+                return (result_type) std::rand();
+            }
+        };
+    } // namespace v
+
+}} // namespace cds::opt
+
 
 // ****************************************************
 // Options metafunctions
 
 // ****************************************************
 // Options metafunctions
@@ -978,7 +1033,7 @@ namespace cds { namespace opt {
     /// Metafunction to find opt::type_traits option in \p Options list
     /** @headerfile cds/opt/options.h
 
     /// Metafunction to find opt::type_traits option in \p Options list
     /** @headerfile cds/opt/options.h
 
-        If \p Options contains opt::type_traits option then it is the metafunction result.
+        If \p Options contains \p opt::type_traits option then it is the metafunction result.
         Otherwise the result is \p DefaultOptons.
     */
     template <typename DefaultOptions, typename... Options>
         Otherwise the result is \p DefaultOptons.
     */
     template <typename DefaultOptions, typename... Options>