aboutsummaryrefslogtreecommitdiff
path: root/src/std/scoped_allocator.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-07-17 19:23:16 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit84e65c63e7482590d535e86f7660a00ae8a0cecb (patch)
treec79de87b7136e96b977003db85d43e5e676bbfc1 /src/std/scoped_allocator.c
parent85c654a102701958d3748e82ecac9c1bc4dbbcba (diff)
Start on amal program
Fix mutex issue in lhs expr which can cause a deadlock when a file has an error and throws and doesn't close the mutex and another thread waits for that mutex. The mutex can instead be removed and ignore race conditions which are uncommon. This should improve memory usage and performance.
Diffstat (limited to 'src/std/scoped_allocator.c')
-rw-r--r--src/std/scoped_allocator.c30
1 files changed, 1 insertions, 29 deletions
diff --git a/src/std/scoped_allocator.c b/src/std/scoped_allocator.c
index 84ec920..d8acbf6 100644
--- a/src/std/scoped_allocator.c
+++ b/src/std/scoped_allocator.c
@@ -27,15 +27,7 @@ void scoped_allocator_node_deinit(ScopedAllocatorNode *self) {
int scoped_allocator_init(ScopedAllocator *self) {
return_if_error(scoped_allocator_node_init(&self->head));
self->current = &self->head;
- return_if_error(buffer_init(&self->mems, NULL));
- return buffer_init(&self->mutexes, NULL);
-}
-
-static void buffer_deinit(Buffer *self) {
- am_free(self->data);
- self->data = NULL;
- self->size = 0;
- self->capacity = 0;
+ return buffer_init(&self->mems, NULL);
}
static void scoped_allocator_deinit_buffers(ScopedAllocator *self) {
@@ -50,22 +42,9 @@ static void scoped_allocator_deinit_buffers(ScopedAllocator *self) {
buffer_deinit(&self->mems);
}
-static void scoped_allocator_deinit_mutexes(ScopedAllocator *self) {
- amal_mutex **mutex;
- amal_mutex **mutexes_end;
- mutex = buffer_begin(&self->mutexes);
- mutexes_end = buffer_end(&self->mutexes);
- while(mutex != mutexes_end) {
- amal_mutex_deinit(*mutex);
- ++mutex;
- }
- buffer_deinit(&self->mutexes);
-}
-
void scoped_allocator_deinit(ScopedAllocator *self) {
self->current = NULL;
scoped_allocator_deinit_buffers(self);
- scoped_allocator_deinit_mutexes(self);
scoped_allocator_node_deinit(&self->head);
}
@@ -129,10 +108,3 @@ int scoped_allocator_add_mem(ScopedAllocator *self, usize *result_index) {
*result_index = buffer_get_size(&self->mems, sizeof(void*));
return buffer_append(&self->mems, &null_data, sizeof(void*));
}
-
-int scoped_allocator_create_mutex(ScopedAllocator *self, amal_mutex **mutex) {
- *mutex = NULL;
- return_if_error(scoped_allocator_alloc(self, sizeof(amal_mutex), (void**)mutex));
- amal_mutex_init(*mutex);
- return buffer_append(&self->mutexes, mutex, sizeof(amal_mutex*));
-}