From 84e65c63e7482590d535e86f7660a00ae8a0cecb Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 17 Jul 2019 19:23:16 +0200 Subject: 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. --- src/std/scoped_allocator.c | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) (limited to 'src/std/scoped_allocator.c') 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*)); -} -- cgit v1.2.3