From 7774786ae6901532b2a66caccf8e267465cdbe90 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Wed, 13 Dec 2023 23:11:15 +0100 Subject: [PATCH] remove `last_item` member and replace with get_last_item() --- redGrapes/util/chunked_list.hpp | 37 ++++++++++++++------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/redGrapes/util/chunked_list.hpp b/redGrapes/util/chunked_list.hpp index 379a0ee4..e0c48d5c 100644 --- a/redGrapes/util/chunked_list.hpp +++ b/redGrapes/util/chunked_list.hpp @@ -236,11 +236,6 @@ struct ChunkedList */ std::atomic< Item * > first_item; - /* points to the latest item which was inserted - * and is already fully initialized - */ - std::atomic< Item * > last_item; - /* points to the next free storage slot, * if available. Will be used to add a new element */ @@ -250,7 +245,6 @@ struct ChunkedList Chunk( memory::Block blk ) : first_item( (Item*) blk.ptr ) - , last_item( ((Item*)blk.ptr) - 1 ) , next_item( (Item*) blk.ptr ) { for(Item * item = this->first_item; item < ( this->first_item + T_chunk_size ); item++ ) @@ -267,6 +261,17 @@ struct ChunkedList { return first_item; } + + /* returns the latest item which was inserted + */ + Item * get_last_item() + { + Item * limit = first_item + T_chunk_size; + if( next_item < limit ) + return next_item; + else + return limit; + } }; template < bool is_const > @@ -300,7 +305,7 @@ struct ChunkedList { return ((bool)chunk) && ( get_item_ptr() >= chunk->first_item ) - && ( get_item_ptr() <= chunk->last_item ); + && ( get_item_ptr() <= chunk->first_item+T_chunk_size ); } /*! @@ -365,7 +370,7 @@ struct ChunkedList { ++chunk; if( chunk ) - cur_item = (uintptr_t) chunk->last_item.load(); + cur_item = (uintptr_t) chunk->get_last_item(); else cur_item = 0; } @@ -472,7 +477,7 @@ struct ChunkedList { ++ this->chunk; if( this->chunk ) - this->cur_item = (uintptr_t) this->chunk->last_item.load(); + this->cur_item = (uintptr_t) this->chunk->get_last_item(); else this->cur_item = 0; } @@ -533,15 +538,7 @@ struct ChunkedList { /* successfully allocated a slot in the current chunk */ - - // initialize item value *next_item = item; - - /* allow iteration to start at the newly initialized item. - * in case it happens that - */ - chunk->last_item ++; - return MutBackwardIterator( chunk, next_item ); } else if ( (uintptr_t)next_item == (uintptr_t)chunk_end ) @@ -617,9 +614,7 @@ struct ChunkedList auto c = chunks.rbegin(); return MutBackwardIterator( c, - ( c != chunks.rend() ) ? c->last_item.load() : nullptr -// TODO: change to this when `last_item` is removed -// ( c != chunks.rend() ) ? min(c->last_item.load()-1, c->first_item+T_chunk_size) : nullptr + ( c != chunks.rend() ) ? c->get_last_item() : nullptr ); } @@ -636,7 +631,7 @@ struct ChunkedList auto c = chunks.rbegin(); return ConstBackwardIterator( c, - ( c != chunks.rend() ) ? c->last_item.load() : nullptr + ( c != chunks.rend() ) ? c->get_last_item() : nullptr ); }