From aaf811669b8744b4a3562c725297ab7fe85a99cc Mon Sep 17 00:00:00 2001 From: khizmax Date: Mon, 16 Jan 2017 11:42:11 +0300 Subject: [PATCH] Fixed some CppCheck warnings in new HP and DHP implementations --- cds/gc/details/hp_common.h | 2 +- cds/gc/dhp_smr.h | 14 ++++++++------ cds/gc/hp_smr.h | 5 ++++- src/dhp.cpp | 8 ++++---- src/hp.cpp | 9 +++++---- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/cds/gc/details/hp_common.h b/cds/gc/details/hp_common.h index bfdccefa..be180677 100644 --- a/cds/gc/details/hp_common.h +++ b/cds/gc/details/hp_common.h @@ -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; } diff --git a/cds/gc/dhp_smr.h b/cds/gc/dhp_smr.h index 92d9b53d..d8c3e9f6 100644 --- a/cds/gc/dhp_smr.h +++ b/cds/gc/dhp_smr.h @@ -213,12 +213,12 @@ namespace cds { namespace gc { : next_( nullptr ) {} - retired_ptr* first() + retired_ptr* first() const { - return reinterpret_cast( this + 1 ); + return reinterpret_cast( const_cast( this ) + 1 ); } - retired_ptr* last() + retired_ptr* last() const { return first() + c_capacity; } @@ -370,6 +370,8 @@ namespace cds { namespace gc { atomics::atomic 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 ) { diff --git a/cds/gc/hp_smr.h b/cds/gc/hp_smr.h index 9d7aa488..2fb7c307 100644 --- a/cds/gc/hp_smr.h +++ b/cds/gc/hp_smr.h @@ -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 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(); diff --git a/src/dhp.cpp b/src/dhp.cpp index 2e8ef2a1..b81b96a3 100644 --- a/src/dhp.cpp +++ b/src/dhp.cpp @@ -63,14 +63,14 @@ namespace cds { namespace gc { namespace dhp { allocator() {} allocator( allocator const& ) {} template - allocator( allocator const& ) {} + explicit allocator( allocator const& ) {} - T* allocate( size_t nCount ) + static T* allocate( size_t nCount ) { return reinterpret_cast( 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( 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(); diff --git a/src/hp.cpp b/src/hp.cpp index 1b0259d7..897e119a 100644 --- a/src/hp.cpp +++ b/src/hp.cpp @@ -59,14 +59,14 @@ namespace cds { namespace gc { namespace hp { allocator() {} allocator( allocator const& ) {} template - allocator( allocator const& ) {} + explicit allocator( allocator const& ) {} - T* allocate( size_t nCount ) + static T* allocate( size_t nCount ) { return reinterpret_cast( 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( 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( pThreadRec ); -- 2.34.1