aboutsummaryrefslogtreecommitdiff
path: root/src/std
diff options
context:
space:
mode:
Diffstat (limited to 'src/std')
-rw-r--r--src/std/buffer.c8
-rw-r--r--src/std/hash_map.c2
-rw-r--r--src/std/scoped_allocator.c30
3 files changed, 10 insertions, 30 deletions
diff --git a/src/std/buffer.c b/src/std/buffer.c
index 3676cee..f4e93e5 100644
--- a/src/std/buffer.c
+++ b/src/std/buffer.c
@@ -17,6 +17,14 @@ int buffer_init(Buffer *self, struct ScopedAllocator *allocator) {
}
}
+void buffer_deinit(Buffer *self) {
+ assert(!self->allocator && "Can't deinit buffer if it has an allocator");
+ am_free(self->data);
+ self->data = NULL;
+ self->size = 0;
+ self->capacity = 0;
+}
+
static CHECK_RESULT int buffer_ensure_capacity(Buffer *self, usize new_capacity) {
usize capacity;
void *new_mem;
diff --git a/src/std/hash_map.c b/src/std/hash_map.c
index d13bf3d..1ad0dea 100644
--- a/src/std/hash_map.c
+++ b/src/std/hash_map.c
@@ -202,7 +202,7 @@ bool hash_map_get(HashMap *self, BufferView key, void *value) {
#define MIN(a, b) ((a) < (b) ? (a) : (b))
-int hash_compare_string(const void *a, const void *b) {
+int hash_map_compare_string(const void *a, const void *b) {
const BufferView *lhs;
const BufferView *rhs;
int mem_diff;
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*));
-}