Skip to content

Commit

Permalink
remove last_item member and replace with get_last_item()
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsippel committed Dec 13, 2023
1 parent 2fc327e commit 7774786
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions redGrapes/util/chunked_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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++ )
Expand All @@ -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 >
Expand Down Expand Up @@ -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 );
}

/*!
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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
);
}

Expand All @@ -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
);
}

Expand Down

0 comments on commit 7774786

Please sign in to comment.