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 ); }