mirror of
https://github.com/justinian/jsix.git
synced 2025-12-12 01:14:31 -08:00
[kutil] Protect heap allocation with a spinlock
Don't allow multiple cores to access the heap datastructures at once.
This commit is contained in:
@@ -89,6 +89,8 @@ heap_allocator::allocate(size_t length)
|
||||
if (order > max_order)
|
||||
return nullptr;
|
||||
|
||||
scoped_lock lock {m_lock};
|
||||
|
||||
mem_header *header = pop_free(order);
|
||||
header->set_used(true);
|
||||
m_allocated_size += (1 << order);
|
||||
@@ -104,6 +106,8 @@ heap_allocator::free(void *p)
|
||||
kassert(addr >= m_start && addr < m_end,
|
||||
"Attempt to free non-heap pointer");
|
||||
|
||||
scoped_lock lock {m_lock};
|
||||
|
||||
mem_header *header = reinterpret_cast<mem_header *>(p);
|
||||
header -= 1; // p points after the header
|
||||
header->set_used(false);
|
||||
|
||||
Reference in New Issue
Block a user