Fixed some CppCheck warnings in new HP and DHP implementations
authorkhizmax <khizmax@gmail.com>
Mon, 16 Jan 2017 08:42:11 +0000 (11:42 +0300)
committerkhizmax <khizmax@gmail.com>
Mon, 16 Jan 2017 08:42:11 +0000 (11:42 +0300)
cds/gc/details/hp_common.h
cds/gc/dhp_smr.h
cds/gc/hp_smr.h
src/dhp.cpp
src/hp.cpp

index bfdccefa012c97828fcb6d19036f021845658ec3..be180677bfa2415014474019026bb35a33249807 100644 (file)
@@ -123,7 +123,7 @@ namespace cds { namespace gc { namespace hp { namespace common {
             : arr_{ nullptr }
         {}
 
-        constexpr size_t capacity() const
+        static constexpr size_t capacity()
         {
             return c_nCapacity;
         }
index 92d9b53ddca5800d4ed12c5f60e893cd932e1ac0..d8c3e9f6ab946903d7d87dcea68b71718444d7c6 100644 (file)
@@ -213,12 +213,12 @@ namespace cds { namespace gc {
                 : next_( nullptr )
             {}
 
-            retired_ptr*    first()
+            retired_ptr* first() const
             {
-                return reinterpret_cast<retired_ptr*>( this + 1 );
+                return reinterpret_cast<retired_ptr*>( const_cast<retired_block*>( this ) + 1 );
             }
 
-            retired_ptr*    last()
+            retired_ptr* last() const
             {
                 return first() + c_capacity;
             }
@@ -370,6 +370,8 @@ namespace cds { namespace gc {
             atomics::atomic<unsigned int> sync_; ///< dummy var to introduce synchronizes-with relationship between threads
             char pad2_[cds::c_nCacheLineSize];
 
+            // CppCheck warn: pad1_ and pad2_ is uninitialized in ctor
+            // cppcheck-suppress uninitMemberVar
             thread_data( guard* guards, size_t guard_count )
                 : hazards_( guards, guard_count )
                 , sync_( 0 )
@@ -504,7 +506,7 @@ namespace cds { namespace gc {
             }
 
         private:
-            CDS_EXPORT_API smr(
+            CDS_EXPORT_API explicit smr(
                 size_t nInitialHazardPtrCount
             );
 
@@ -515,7 +517,7 @@ namespace cds { namespace gc {
         private:
             //@cond
             CDS_EXPORT_API thread_record* create_thread_data();
-            CDS_EXPORT_API void destroy_thread_data( thread_record* pRec );
+            static CDS_EXPORT_API void destroy_thread_data( thread_record* pRec );
 
             /// Allocates Hazard Pointer SMR thread private data
             CDS_EXPORT_API thread_record* alloc_thread_data();
@@ -1205,7 +1207,7 @@ namespace cds { namespace gc {
                 By perforce the local thread's guard pool is grown automatically from common pool.
                 When the thread terminated its guard pool is backed to common GC's pool.
         */
-        DHP(
+        explicit DHP(
             size_t nInitialHazardPtrCount = 16  ///< Initial number of hazard pointer per thread
         )
         {
index 9d7aa488fabd1f0d4750cb0622ea9f9868038996..2fb7c307d782aaade59acecd6ec3805c15c50c4c 100644 (file)
@@ -156,6 +156,7 @@ namespace cds { namespace gc {
                 free_head_ = gList;
             }
 
+            // cppcheck-suppress functionConst
             void clear()
             {
                 for ( guard* cur = array_, *last = array_ + capacity(); cur < last; ++cur )
@@ -294,6 +295,8 @@ namespace cds { namespace gc {
             atomics::atomic<unsigned int> sync_; ///< dummy var to introduce synchronizes-with relationship between threads
             char pad2_[cds::c_nCacheLineSize];
 
+            // CppCheck warn: pad1_ and pad2_ is uninitialized in ctor
+            // cppcheck-suppress uninitMemberVar
             thread_data( guard* guards, size_t guard_count, retired_ptr* retired_arr, size_t retired_capacity )
                 : hazards_( guards, guard_count )
                 , retired_( retired_arr, retired_capacity )
@@ -534,7 +537,7 @@ namespace cds { namespace gc {
         private:
             //@cond
             CDS_EXPORT_API thread_record* create_thread_data();
-            CDS_EXPORT_API void destroy_thread_data( thread_record* pRec );
+            static CDS_EXPORT_API void destroy_thread_data( thread_record* pRec );
 
             /// Allocates Hazard Pointer SMR thread private data
             CDS_EXPORT_API thread_record* alloc_thread_data();
index 2e8ef2a10c2e330a647f5dc37159a26eb2acfee4..b81b96a364f8a8c01e473433e01725432aca60d1 100644 (file)
@@ -63,14 +63,14 @@ namespace cds { namespace gc { namespace dhp {
             allocator() {}
             allocator( allocator const& ) {}
             template <class U>
-            allocator( allocator<U> const& ) {}
+            explicit allocator( allocator<U> const& ) {}
 
-            T* allocate( size_t nCount )
+            static T* allocate( size_t nCount )
             {
                 return reinterpret_cast<T*>( s_alloc_memory( sizeof( value_type ) * nCount ));
             }
 
-            void deallocate( T* p, size_t /*nCount*/ )
+            static void deallocate( T* p, size_t /*nCount*/ )
             {
                 s_free_memory( reinterpret_cast<void*>( p ));
             }
@@ -282,7 +282,7 @@ namespace cds { namespace gc { namespace dhp {
         );
     }
 
-    CDS_EXPORT_API void smr::destroy_thread_data( thread_record* pRec )
+    /*static*/ CDS_EXPORT_API void smr::destroy_thread_data( thread_record* pRec )
     {
         // all retired pointers must be freed
         pRec->~thread_record();
index 1b0259d7e0a354ae51d4041645d17a951b535f8f..897e119a867f5b6139205b16967c0cacc527c958 100644 (file)
@@ -59,14 +59,14 @@ namespace cds { namespace gc { namespace hp {
             allocator() {}
             allocator( allocator const& ) {}
             template <class U>
-            allocator( allocator<U> const& ) {}
+            explicit allocator( allocator<U> const& ) {}
 
-            T* allocate( size_t nCount )
+            static T* allocate( size_t nCount )
             {
                 return reinterpret_cast<T*>( s_alloc_memory( sizeof( value_type ) * nCount ) );
             }
 
-            void deallocate( T* p, size_t /*nCount*/ )
+            static void deallocate( T* p, size_t /*nCount*/ )
             {
                 s_free_memory( reinterpret_cast<void*>( p ) );
             }
@@ -213,7 +213,7 @@ namespace cds { namespace gc { namespace hp {
         );
     }
 
-    CDS_EXPORT_API void smr::destroy_thread_data( thread_record* pRec )
+    /*static*/ CDS_EXPORT_API void smr::destroy_thread_data( thread_record* pRec )
     {
         // all retired pointers must be freed
         assert( pRec->retired_.size() == 0 );
@@ -381,6 +381,7 @@ namespace cds { namespace gc { namespace hp {
         }
     }
 
+    // cppcheck-suppress functionConst
     CDS_EXPORT_API void smr::classic_scan( thread_data* pThreadRec )
     {
         thread_record* pRec = static_cast<thread_record*>( pThreadRec );