Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/ubench.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#include "ubench.h"
// BENCHMARK CONFIG
#define N_ITERATIONS 1000
#define ALLOC_SIZE (util_get_page_size())
#define ALLOC_SIZE (utils_get_page_size())

// OS MEMORY PROVIDER CONFIG
#define OS_MEMORY_PROVIDER_TRACE (0)
Expand Down
24 changes: 12 additions & 12 deletions src/base_alloc/base_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct umf_ba_chunk_t {
struct umf_ba_main_pool_meta_t {
size_t pool_size; // size of each pool (argument of each ba_os_alloc() call)
size_t chunk_size; // size of all memory chunks in this pool
os_mutex_t free_lock; // lock of free_list
utils_mutex_t free_lock; // lock of free_list
umf_ba_chunk_t *free_list; // list of free chunks
size_t n_allocs; // number of allocated chunks
#ifndef NDEBUG
Expand Down Expand Up @@ -135,7 +135,7 @@ static void *ba_os_alloc_annotated(size_t pool_size) {

umf_ba_pool_t *umf_ba_create(size_t size) {
size_t chunk_size = ALIGN_UP(size, MEMORY_ALIGNMENT);
size_t mutex_size = ALIGN_UP(util_mutex_get_size(), MEMORY_ALIGNMENT);
size_t mutex_size = ALIGN_UP(utils_mutex_get_size(), MEMORY_ALIGNMENT);

size_t metadata_size = sizeof(struct umf_ba_main_pool_meta_t);
size_t pool_size = sizeof(void *) + metadata_size + mutex_size +
Expand Down Expand Up @@ -168,10 +168,10 @@ umf_ba_pool_t *umf_ba_create(size_t size) {
char *data_ptr = (char *)&pool->data;
size_t size_left = pool_size - offsetof(umf_ba_pool_t, data);

util_align_ptr_size((void **)&data_ptr, &size_left, MEMORY_ALIGNMENT);
utils_align_ptr_size((void **)&data_ptr, &size_left, MEMORY_ALIGNMENT);

// init free_lock
os_mutex_t *mutex = util_mutex_init(&pool->metadata.free_lock);
utils_mutex_t *mutex = utils_mutex_init(&pool->metadata.free_lock);
if (!mutex) {
ba_os_free(pool, pool_size);
return NULL;
Expand All @@ -184,13 +184,13 @@ umf_ba_pool_t *umf_ba_create(size_t size) {
}

void *umf_ba_alloc(umf_ba_pool_t *pool) {
util_mutex_lock(&pool->metadata.free_lock);
utils_mutex_lock(&pool->metadata.free_lock);
if (pool->metadata.free_list == NULL) {
umf_ba_next_pool_t *new_pool =
(umf_ba_next_pool_t *)ba_os_alloc_annotated(
pool->metadata.pool_size);
if (!new_pool) {
util_mutex_unlock(&pool->metadata.free_lock);
utils_mutex_unlock(&pool->metadata.free_lock);
return NULL;
}

Expand All @@ -209,7 +209,7 @@ void *umf_ba_alloc(umf_ba_pool_t *pool) {
size_t size_left =
pool->metadata.pool_size - offsetof(umf_ba_next_pool_t, data);

util_align_ptr_size((void **)&data_ptr, &size_left, MEMORY_ALIGNMENT);
utils_align_ptr_size((void **)&data_ptr, &size_left, MEMORY_ALIGNMENT);
ba_divide_memory_into_chunks(pool, data_ptr, size_left);
}

Expand All @@ -234,7 +234,7 @@ void *umf_ba_alloc(umf_ba_pool_t *pool) {
VALGRIND_DO_MALLOCLIKE_BLOCK(chunk, pool->metadata.chunk_size, 0, 0);
utils_annotate_memory_undefined(chunk, pool->metadata.chunk_size);

util_mutex_unlock(&pool->metadata.free_lock);
utils_mutex_unlock(&pool->metadata.free_lock);

return chunk;
}
Expand Down Expand Up @@ -269,7 +269,7 @@ void umf_ba_free(umf_ba_pool_t *pool, void *ptr) {

umf_ba_chunk_t *chunk = (umf_ba_chunk_t *)ptr;

util_mutex_lock(&pool->metadata.free_lock);
utils_mutex_lock(&pool->metadata.free_lock);
assert(pool_contains_pointer(pool, ptr));
chunk->next = pool->metadata.free_list;
pool->metadata.free_list = chunk;
Expand All @@ -281,14 +281,14 @@ void umf_ba_free(umf_ba_pool_t *pool, void *ptr) {
VALGRIND_DO_FREELIKE_BLOCK(chunk, 0);
utils_annotate_memory_inaccessible(chunk, pool->metadata.chunk_size);

util_mutex_unlock(&pool->metadata.free_lock);
utils_mutex_unlock(&pool->metadata.free_lock);
}

void umf_ba_destroy(umf_ba_pool_t *pool) {
// Do not destroy if we are running in the proxy library,
// because it may need those resources till
// the very end of exiting the application.
if (pool->metadata.n_allocs && util_is_running_in_proxy_lib()) {
if (pool->metadata.n_allocs && utils_is_running_in_proxy_lib()) {
return;
}

Expand All @@ -308,6 +308,6 @@ void umf_ba_destroy(umf_ba_pool_t *pool) {
ba_os_free(current_pool, size);
}

util_mutex_destroy_not_free(&pool->metadata.free_lock);
utils_mutex_destroy_not_free(&pool->metadata.free_lock);
ba_os_free(pool, size);
}
2 changes: 1 addition & 1 deletion src/base_alloc/base_alloc_global.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static void *get_original_alloc(void *user_ptr, size_t *total_size,
}

void *umf_ba_global_aligned_alloc(size_t size, size_t alignment) {
util_init_once(&ba_is_initialized, umf_ba_create_global);
utils_init_once(&ba_is_initialized, umf_ba_create_global);

if (size == 0) {
return NULL;
Expand Down
34 changes: 17 additions & 17 deletions src/base_alloc/base_alloc_linear.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef struct umf_ba_next_linear_pool_t umf_ba_next_linear_pool_t;
// metadata is set and used only in the main (the first) pool
typedef struct umf_ba_main_linear_pool_meta_t {
size_t pool_size; // size of this pool (argument of ba_os_alloc() call)
os_mutex_t lock;
utils_mutex_t lock;
char *data_ptr;
size_t size_left;
size_t pool_n_allocs; // number of allocations in this pool
Expand Down Expand Up @@ -98,7 +98,7 @@ umf_ba_linear_pool_t *umf_ba_linear_create(size_t pool_size) {
void *data_ptr = &pool->data;
size_t size_left = pool_size - offsetof(umf_ba_linear_pool_t, data);

util_align_ptr_size(&data_ptr, &size_left, MEMORY_ALIGNMENT);
utils_align_ptr_size(&data_ptr, &size_left, MEMORY_ALIGNMENT);

pool->metadata.pool_size = pool_size;
pool->metadata.data_ptr = data_ptr;
Expand All @@ -109,7 +109,7 @@ umf_ba_linear_pool_t *umf_ba_linear_create(size_t pool_size) {
_DEBUG_EXECUTE(pool->metadata.global_n_allocs = 0);

// init lock
os_mutex_t *lock = util_mutex_init(&pool->metadata.lock);
utils_mutex_t *lock = utils_mutex_init(&pool->metadata.lock);
if (!lock) {
ba_os_free(pool, pool_size);
return NULL;
Expand All @@ -123,7 +123,7 @@ void *umf_ba_linear_alloc(umf_ba_linear_pool_t *pool, size_t size) {
return NULL;
}
size_t aligned_size = ALIGN_UP(size, MEMORY_ALIGNMENT);
util_mutex_lock(&pool->metadata.lock);
utils_mutex_lock(&pool->metadata.lock);
if (pool->metadata.size_left < aligned_size) {
size_t pool_size = MINIMUM_LINEAR_POOL_SIZE;
size_t usable_size =
Expand All @@ -139,7 +139,7 @@ void *umf_ba_linear_alloc(umf_ba_linear_pool_t *pool, size_t size) {
umf_ba_next_linear_pool_t *new_pool =
(umf_ba_next_linear_pool_t *)ba_os_alloc(pool_size);
if (!new_pool) {
util_mutex_unlock(&pool->metadata.lock);
utils_mutex_unlock(&pool->metadata.lock);
return NULL;
}

Expand All @@ -149,7 +149,7 @@ void *umf_ba_linear_alloc(umf_ba_linear_pool_t *pool, size_t size) {
void *data_ptr = &new_pool->data;
size_t size_left =
new_pool->pool_size - offsetof(umf_ba_next_linear_pool_t, data);
util_align_ptr_size(&data_ptr, &size_left, MEMORY_ALIGNMENT);
utils_align_ptr_size(&data_ptr, &size_left, MEMORY_ALIGNMENT);

pool->metadata.data_ptr = data_ptr;
pool->metadata.size_left = size_left;
Expand All @@ -171,7 +171,7 @@ void *umf_ba_linear_alloc(umf_ba_linear_pool_t *pool, size_t size) {
}
_DEBUG_EXECUTE(pool->metadata.global_n_allocs++);
_DEBUG_EXECUTE(ba_debug_checks(pool));
util_mutex_unlock(&pool->metadata.lock);
utils_mutex_unlock(&pool->metadata.lock);

return ptr;
}
Expand All @@ -188,7 +188,7 @@ static inline int pool_contains_ptr(void *pool, size_t pool_size,
// 0 - ptr belonged to the pool and was freed
// -1 - ptr doesn't belong to the pool and wasn't freed
int umf_ba_linear_free(umf_ba_linear_pool_t *pool, void *ptr) {
util_mutex_lock(&pool->metadata.lock);
utils_mutex_lock(&pool->metadata.lock);
_DEBUG_EXECUTE(ba_debug_checks(pool));
if (pool_contains_ptr(pool, pool->metadata.pool_size, pool->data, ptr)) {
pool->metadata.pool_n_allocs--;
Expand All @@ -204,7 +204,7 @@ int umf_ba_linear_free(umf_ba_linear_pool_t *pool, void *ptr) {
pool->metadata.pool_size = page_size;
}
_DEBUG_EXECUTE(ba_debug_checks(pool));
util_mutex_unlock(&pool->metadata.lock);
utils_mutex_unlock(&pool->metadata.lock);
return 0;
}

Expand All @@ -227,14 +227,14 @@ int umf_ba_linear_free(umf_ba_linear_pool_t *pool, void *ptr) {
ba_os_free(next_pool_ptr, size);
}
_DEBUG_EXECUTE(ba_debug_checks(pool));
util_mutex_unlock(&pool->metadata.lock);
utils_mutex_unlock(&pool->metadata.lock);
return 0;
}
prev_pool = next_pool;
next_pool = next_pool->next_pool;
}

util_mutex_unlock(&pool->metadata.lock);
utils_mutex_unlock(&pool->metadata.lock);
// ptr doesn't belong to the pool and wasn't freed
return -1;
}
Expand All @@ -243,7 +243,7 @@ void umf_ba_linear_destroy(umf_ba_linear_pool_t *pool) {
// Do not destroy if we are running in the proxy library,
// because it may need those resources till
// the very end of exiting the application.
if (util_is_running_in_proxy_lib()) {
if (utils_is_running_in_proxy_lib()) {
return;
}

Expand All @@ -262,7 +262,7 @@ void umf_ba_linear_destroy(umf_ba_linear_pool_t *pool) {
ba_os_free(current_pool, current_pool->pool_size);
}

util_mutex_destroy_not_free(&pool->metadata.lock);
utils_mutex_destroy_not_free(&pool->metadata.lock);
ba_os_free(pool, pool->metadata.pool_size);
}

Expand All @@ -272,12 +272,12 @@ void umf_ba_linear_destroy(umf_ba_linear_pool_t *pool) {
// to the end of the pool if ptr belongs to the pool
size_t umf_ba_linear_pool_contains_pointer(umf_ba_linear_pool_t *pool,
void *ptr) {
util_mutex_lock(&pool->metadata.lock);
utils_mutex_lock(&pool->metadata.lock);
char *cptr = (char *)ptr;
if (cptr >= pool->data &&
cptr < ((char *)(pool)) + pool->metadata.pool_size) {
size_t size = ((char *)(pool)) + pool->metadata.pool_size - cptr;
util_mutex_unlock(&pool->metadata.lock);
utils_mutex_unlock(&pool->metadata.lock);
return size;
}

Expand All @@ -286,12 +286,12 @@ size_t umf_ba_linear_pool_contains_pointer(umf_ba_linear_pool_t *pool,
if (cptr >= next_pool->data &&
cptr < ((char *)(next_pool)) + next_pool->pool_size) {
size_t size = ((char *)(next_pool)) + next_pool->pool_size - cptr;
util_mutex_unlock(&pool->metadata.lock);
utils_mutex_unlock(&pool->metadata.lock);
return size;
}
next_pool = next_pool->next_pool;
}

util_mutex_unlock(&pool->metadata.lock);
utils_mutex_unlock(&pool->metadata.lock);
return 0;
}
2 changes: 1 addition & 1 deletion src/base_alloc/base_alloc_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ void ba_os_free(void *ptr, size_t size) {
static void _ba_os_init_page_size(void) { Page_size = sysconf(_SC_PAGE_SIZE); }

size_t ba_os_get_page_size(void) {
util_init_once(&Page_size_is_initialized, _ba_os_init_page_size);
utils_init_once(&Page_size_is_initialized, _ba_os_init_page_size);
return Page_size;
}
2 changes: 1 addition & 1 deletion src/base_alloc/base_alloc_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ static void _ba_os_init_page_size(void) {
}

size_t ba_os_get_page_size(void) {
util_init_once(&Page_size_is_initialized, _ba_os_init_page_size);
utils_init_once(&Page_size_is_initialized, _ba_os_init_page_size);
return Page_size;
}
Loading
Loading