Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize memory layout #39

Draft
wants to merge 9 commits into
base: dev
Choose a base branch
from
Prev Previous commit
Next Next commit
AtomicList::ItemControlBlock: use bitmagic to store deleted-flag in…
… `item_data_ptr`
michaelsippel committed Feb 1, 2024
commit d10019d69f21744e4688e5a31e7a45a53455ae65
13 changes: 9 additions & 4 deletions redGrapes/util/atomic_list.hpp
Original file line number Diff line number Diff line change
@@ -61,7 +61,6 @@ namespace redGrapes
{
using Guard = typename Refcounted<ItemControlBlock, ItemControlBlockDeleter>::Guard;

bool volatile deleted;
Guard prev;
uintptr_t item_data_ptr;
Allocator alloc;
@@ -89,12 +88,18 @@ namespace redGrapes
*/
inline void erase()
{
deleted = true;
// set MSB (most significant bit) of item_data ptr
item_data_ptr |= ~(~(uintptr_t) 0 >> 1);
}

inline bool is_deleted() const
{
return item_data_ptr & ~(~(uintptr_t) 0 >> 1);
}

inline Item* get() const
{
return (Item*) item_data_ptr;
return (Item*) (item_data_ptr & (~(uintptr_t) 0 >> 1));
}

/* adjusts `prev` so that it points to a non-deleted chunk again
@@ -104,7 +109,7 @@ namespace redGrapes
void skip_deleted_prev()
{
Guard p = prev;
while(p && p->deleted)
while(p && p->is_deleted())
p = p->prev;

prev = p;