Skip to content

Commit

Permalink
fix bug in freeSlots
Browse files Browse the repository at this point in the history
  • Loading branch information
caseymcc committed Jul 8, 2022
1 parent 801ad22 commit 399ba9a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/FastNoise/SmartNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,20 @@ namespace FastNoise

assert( freeSlots[idx].size >= slotSize );

new( startSlot ) SlotHeader { 0u };
usedSlots.emplace_back( Slot{ freeSlots[idx].pos, slotSize } );

// Check if remaining free slot is empty
if( freeSlots[idx].size <= slotSize )
{
assert( freeSlots[idx].size == slotSize );
freeSlots.erase( freeSlots.cbegin() + idx );
return ptr;
}

freeSlots[idx].pos += slotSize;
freeSlots[idx].size -= slotSize;

new( startSlot ) SlotHeader { 0u };

return ptr;
}
}
Expand Down Expand Up @@ -273,6 +273,8 @@ namespace FastNoise

std::atomic<uint32_t>& GetReferenceCount( SmartNodeReference ref ) const
{
std::lock_guard lock( mMutex );

return std::next( mPools.begin(), ref.u32.pool )->GetReferenceCount( ref.u32.id );
}

Expand Down Expand Up @@ -339,7 +341,7 @@ namespace FastNoise
// std::list is used to allow lock free reads to pools
// In most use cases there should only be 1 pool so performance is not a concern
std::list<SmartNodeManagerPool> mPools;
std::mutex mMutex;
mutable std::mutex mMutex;
};

static SmartNodeMemoryAllocator gMemoryAllocator;
Expand Down

0 comments on commit 399ba9a

Please sign in to comment.