blob: 60abccee50328483af0aed49b69a9ac05af82fd6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#ifndef AMALGAM_SCOPED_ALLOCATOR_H
#define AMALGAM_SCOPED_ALLOCATOR_H
#include "defs.h"
#include "misc.h"
#include "types.h"
#include "buffer.h"
struct ScopedAllocatorNode {
char *data;
usize size;
ScopedAllocatorNode *next;
};
struct ScopedAllocator {
ScopedAllocatorNode head;
ScopedAllocatorNode *current;
Buffer/*<void*>*/ mems;
/* TODO: Use linked-list instead, since the elements are dynamically allocated anyways */
/* Find another way to store mutexes */
Buffer/*<amal_mutex*>*/ mutexes;
};
CHECK_RESULT int scoped_allocator_node_init(ScopedAllocatorNode *self);
void scoped_allocator_node_deinit(ScopedAllocatorNode *self);
CHECK_RESULT int scoped_allocator_init(ScopedAllocator *self);
void scoped_allocator_deinit(ScopedAllocator *self);
CHECK_RESULT int scoped_allocator_alloc(ScopedAllocator *self, usize size, void **mem);
CHECK_RESULT int scoped_allocator_add_mem(ScopedAllocator *self, usize *result_index);
CHECK_RESULT int scoped_allocator_create_mutex(ScopedAllocator *self, amal_mutex **mutex);
#endif
|