diff options
Diffstat (limited to 'src/allocator.c')
| -rw-r--r-- | src/allocator.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/allocator.c b/src/allocator.c index ffb6763..bddc5e5 100644 --- a/src/allocator.c +++ b/src/allocator.c @@ -5,17 +5,30 @@ allocator create_allocator(uint64_t size) { allocator.cursor = 0; allocator.size = size; allocator.memory = mem_alloc(size); + allocator.mutex = mutex_create(); return allocator; } void* allocator_alloc(allocator* al, uint64_t size) { + mutex_lock(&al->mutex); if (al->cursor + size < al->size) { al->cursor += size; - return al->memory + al->cursor - size; + void* result = al->memory + al->cursor - size; + mutex_unlock(&al->mutex); + return result; } log_assert(0, "Allocator out of space"); + mutex_unlock(&al->mutex); } void destroy_allocator(allocator* al) { + mutex_lock(&al->mutex); mem_free(al->memory); + mutex_unlock(&al->mutex); +} + +void allocator_clear(allocator* al) { + mutex_lock(&al->mutex); + al->cursor = 0; + mutex_unlock(&al->mutex); }
\ No newline at end of file |
