mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
[kernel] Lock the heap allocator for part of reallocate
heap_allocator::reallocate relies on the allocate and free methods so mostly doesn't need locking, but it does touch the tracking map, so needs to protect that with a lock.
This commit is contained in:
@@ -111,6 +111,8 @@ heap_allocator::reallocate(void *p, size_t old_length, size_t new_length)
|
|||||||
return allocate(new_length);
|
return allocate(new_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util::scoped_lock lock {m_lock};
|
||||||
|
|
||||||
block_info *info = m_map.find(map_key(p));
|
block_info *info = m_map.find(map_key(p));
|
||||||
kassert(info, "Attempt to reallocate unknown block");
|
kassert(info, "Attempt to reallocate unknown block");
|
||||||
if (!info)
|
if (!info)
|
||||||
@@ -119,6 +121,7 @@ heap_allocator::reallocate(void *p, size_t old_length, size_t new_length)
|
|||||||
if (new_length <= (1 << info->order))
|
if (new_length <= (1 << info->order))
|
||||||
return p;
|
return p;
|
||||||
|
|
||||||
|
lock.release();
|
||||||
void *new_block = allocate(new_length);
|
void *new_block = allocate(new_length);
|
||||||
memcpy(new_block, p, old_length);
|
memcpy(new_block, p, old_length);
|
||||||
free(p);
|
free(p);
|
||||||
|
|||||||
Reference in New Issue
Block a user