Fixed constness, improved doc
authorkhizmax <libcds.dev@gmail.com>
Sat, 19 Mar 2016 09:02:29 +0000 (12:02 +0300)
committerkhizmax <libcds.dev@gmail.com>
Sat, 19 Mar 2016 09:02:29 +0000 (12:02 +0300)
cds/container/impl/skip_list_set.h
cds/container/skip_list_set_nogc.h
cds/container/skip_list_set_rcu.h

index 4b76d9cfdada35cb5b2c5ad46e2f70f6400062c7..5534c7c593b581d882c05b1ea473bbf892f6032f 100644 (file)
@@ -152,6 +152,8 @@ namespace cds { namespace container {
         typedef typename traits::random_level_generator random_level_generator; ///< random level generator
         typedef typename traits::stat             stat;           ///< internal statistics type
 
+        static size_t const c_nHazardPtrCount = base_class::c_nHazardPtrCount; ///< Count of hazard pointer required for the skip-list
+
     protected:
         //@cond
         typedef typename maker::node_type           node_type;
@@ -183,7 +185,50 @@ namespace cds { namespace container {
         {}
 
     public:
+    ///@name Forward iterators (only for debugging purpose)
+    //@{
         /// Iterator type
+        /**
+            The forward iterator has some features:
+            - it has no post-increment operator
+            - to protect the value, the iterator contains a GC-specific guard + another guard is required locally for increment operator.
+              For some GC (like as \p gc::HP), a guard is a limited resource per thread, so an exception (or assertion) "no free guard"
+              may be thrown if the limit of guard count per thread is exceeded.
+            - The iterator cannot be moved across thread boundary because it contains thread-private GC's guard.
+            - Iterator ensures thread-safety even if you delete the item the iterator points to. However, in case of concurrent
+              deleting operations there is no guarantee that you iterate all item in the list. 
+              Moreover, a crash is possible when you try to iterate the next element that has been deleted by concurrent thread.
+
+            @warning Use this iterator on the concurrent container for debugging purpose only.
+
+            The iterator interface:
+            \code
+            class iterator {
+            public:
+                // Default constructor
+                iterator();
+
+                // Copy construtor
+                iterator( iterator const& src );
+
+                // Dereference operator
+                value_type * operator ->() const;
+
+                // Dereference operator
+                value_type& operator *() const;
+
+                // Preincrement operator
+                iterator& operator ++();
+
+                // Assignment operator
+                iterator& operator = (iterator const& src);
+
+                // Equality operators
+                bool operator ==(iterator const& i ) const;
+                bool operator !=(iterator const& i ) const;
+            };
+            \endcode
+        */
         typedef skip_list::details::iterator< typename base_class::iterator >  iterator;
 
         /// Const iterator type
@@ -224,6 +269,7 @@ namespace cds { namespace container {
         {
             return const_iterator( base_class::cend() );
         }
+    //@}
 
     public:
         /// Inserts new node
@@ -578,7 +624,7 @@ namespace cds { namespace container {
         {
             CDS_UNUSED( pred );
             return base_class::find_with( key, cds::details::predicate_wrapper< node_type, Less, typename maker::value_accessor >(),
-                                          [&f]( node_type& node, Q& v ) { f( node.m_Value, v ); } );
+                                          [&f]( node_type& node, Q const& v ) { f( node.m_Value, v ); } );
         }
         //@endcond
 
index ca866b41362e04cf709d1fe374b079ae0351d22e..b337b12a515138ee1865ba8420a32a1cad6884c9 100644 (file)
@@ -199,7 +199,14 @@ namespace cds { namespace container {
         //@endcond
 
     public:
-        /// Iterator type
+    ///@name Forward iterators
+    //@{
+        /// Forward iterator
+        /**
+            The forward iterator for a split-list has some features:
+            - it has no post-increment operator
+            - it depends on iterator of underlying \p OrderedList
+        */
         typedef skip_list::details::iterator< typename base_class::iterator >  iterator;
 
         /// Const iterator type
@@ -212,16 +219,16 @@ namespace cds { namespace container {
         }
 
         /// Returns a forward const iterator addressing the first element in a set
-        //@{
         const_iterator begin() const
         {
             return const_iterator( base_class::begin() );
         }
+
+        /// Returns a forward const iterator addressing the first element in a set
         const_iterator cbegin() const
         {
             return const_iterator( base_class::cbegin() );
         }
-        //@}
 
         /// Returns a forward iterator that addresses the location succeeding the last element in a set.
         iterator end()
@@ -230,16 +237,16 @@ namespace cds { namespace container {
         }
 
         /// Returns a forward const iterator that addresses the location succeeding the last element in a set.
-        //@{
         const_iterator end() const
         {
             return const_iterator( base_class::end() );
         }
+        /// Returns a forward const iterator that addresses the location succeeding the last element in a set.
         const_iterator cend() const
         {
             return const_iterator( base_class::cend() );
         }
-        //@}
+    //@}
 
     protected:
         //@cond
index 29fbb5eef16d0723bc0da4b40d9977d61dadcd7c..f3770e1e7113f5db722b4b2e3c66a7633c592884 100644 (file)
@@ -259,7 +259,17 @@ namespace cds { namespace container {
         {}
 
     public:
-        /// Iterator type
+    ///@name Forward iterators (thread-safe under RCU lock)
+    //@{
+        /// Forward iterator
+        /**
+            The forward iterator has some features:
+            - it has no post-increment operator
+            - it depends on iterator of underlying \p OrderedList
+
+            You may safely use iterators in multi-threaded environment only under RCU lock.
+            Otherwise, a crash is possible if another thread deletes the element the iterator points to.
+        */
         typedef skip_list::details::iterator< typename base_class::iterator >  iterator;
 
         /// Const iterator type
@@ -272,16 +282,16 @@ namespace cds { namespace container {
         }
 
         /// Returns a forward const iterator addressing the first element in a set
-        //@{
         const_iterator begin() const
         {
             return const_iterator( base_class::begin() );
         }
+
+        /// Returns a forward const iterator addressing the first element in a set
         const_iterator cbegin() const
         {
             return const_iterator( base_class::cbegin() );
         }
-        //@}
 
         /// Returns a forward iterator that addresses the location succeeding the last element in a set.
         iterator end()
@@ -290,16 +300,17 @@ namespace cds { namespace container {
         }
 
         /// Returns a forward const iterator that addresses the location succeeding the last element in a set.
-        //@{
         const_iterator end() const
         {
             return const_iterator( base_class::end() );
         }
+
+        /// Returns a forward const iterator that addresses the location succeeding the last element in a set.
         const_iterator cend() const
         {
             return const_iterator( base_class::cend() );
         }
-        //@}
+    //@}
 
     public:
         /// Inserts new node
@@ -621,7 +632,7 @@ namespace cds { namespace container {
         {
             CDS_UNUSED( pred );
             return base_class::find_with( val, cds::details::predicate_wrapper< node_type, Less, typename maker::value_accessor >(),
-                                          [&f]( node_type& node, Q& v ) { f( node.m_Value, v ); } );
+                                          [&f]( node_type& node, Q const& v ) { f( node.m_Value, v ); } );
         }
         //@endcond