Skip to content

Commit

Permalink
Convert indentation to tabs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehpor committed Dec 12, 2024
1 parent 5e65132 commit 3f630cb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion catkit_core/FreeListAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ std::size_t FreeListAllocator::ComputeMetadataBufferSize(std::size_t max_num_blo

void FreeListAllocator::Initialize(std::size_t max_num_blocks, std::size_t alignment, std::size_t buffer_size)
{
std::copy(VERSION, VERSION + sizeof(VERSION), m_Header.version);
std::copy(VERSION, VERSION + sizeof(VERSION), m_Header.version);
m_Header.max_num_blocks = max_num_blocks;
m_Header.alignment = alignment;
m_Header.total_buffer_size = buffer_size;
Expand Down
96 changes: 48 additions & 48 deletions catkit_core/PoolAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,77 +5,77 @@
const std::uint8_t VERSION[4] = {0, 0, 0, 0};

PoolAllocator::PoolAllocator(void *metadata_buffer)
: m_Header(*static_cast<Header *>(metadata_buffer)),
m_Capacity(m_Header.capacity),
m_Head(m_Header.head),
m_Next(reinterpret_cast<std::atomic_uint32_t *>(static_cast<char *>(metadata_buffer) + sizeof(Header)))
: m_Header(*static_cast<Header *>(metadata_buffer)),
m_Capacity(m_Header.capacity),
m_Head(m_Header.head),
m_Next(reinterpret_cast<std::atomic_uint32_t *>(static_cast<char *>(metadata_buffer) + sizeof(Header)))
{
}

void PoolAllocator::Initialize(std::uint32_t capacity)
{
// Set version and capacity.
std::copy(VERSION, VERSION + sizeof(VERSION), m_Header.version);
m_Capacity = capacity;
// Set version and capacity.
std::copy(VERSION, VERSION + sizeof(VERSION), m_Header.version);
m_Capacity = capacity;

// Initialize the linked list.
m_Head.store(0, std::memory_order_relaxed);
// Initialize the linked list.
m_Head.store(0, std::memory_order_relaxed);

for (std::size_t i = 0; i < m_Capacity; ++i)
{
if (i == m_Capacity - 1)
{
m_Next[i] = INVALID_HANDLE;
}
else
{
m_Next[i] = i + 1;
}
}
for (std::size_t i = 0; i < m_Capacity; ++i)
{
if (i == m_Capacity - 1)
{
m_Next[i] = INVALID_HANDLE;
}
else
{
m_Next[i] = i + 1;
}
}
}

std::size_t PoolAllocator::CalculateMetadataBufferSize(std::uint32_t capacity)
{
std::size_t size = sizeof(Header);
size += capacity * sizeof(std::atomic<BlockHandle>);
std::size_t size = sizeof(Header);
size += capacity * sizeof(std::atomic<BlockHandle>);

return size;
return size;
}

PoolAllocator::BlockHandle PoolAllocator::Allocate()
{
BlockHandle head = m_Head.load(std::memory_order_relaxed);
BlockHandle next;
BlockHandle head = m_Head.load(std::memory_order_relaxed);
BlockHandle next;

// Pop the first element from the linked list.
do
{
// Check if the pool is empty.
if (head == INVALID_HANDLE)
{
return INVALID_HANDLE;
}
// Pop the first element from the linked list.
do
{
// Check if the pool is empty.
if (head == INVALID_HANDLE)
{
return INVALID_HANDLE;
}

next = m_Next[head].load(std::memory_order_relaxed);
} while (!m_Head.compare_exchange_weak(head, next));
next = m_Next[head].load(std::memory_order_relaxed);
} while (!m_Head.compare_exchange_weak(head, next));

// Return the popped element.
return head;
// Return the popped element.
return head;
}

void PoolAllocator::Deallocate(BlockHandle index)
{
// Check if the element is within the pool bounds.
if (index >= m_Capacity)
{
return;
}
// Check if the element is within the pool bounds.
if (index >= m_Capacity)
{
return;
}

BlockHandle head = m_Head.load(std::memory_order_relaxed);;
BlockHandle head = m_Head.load(std::memory_order_relaxed);;

// Push the element back on the front of the linked list.
do
{
m_Next[index] = head;
} while (!m_Head.compare_exchange_weak(head, index));
// Push the element back on the front of the linked list.
do
{
m_Next[index] = head;
} while (!m_Head.compare_exchange_weak(head, index));
}

0 comments on commit 3f630cb

Please sign in to comment.