hashers now use thread local arena
Instead of writing directly to file_hashes.txt, hash_workers now are using a local arena, writing everything once at the end using #pragma once to ensure that a given header file is included only once in a single compilation unit
This commit is contained in:
15
arena.c
15
arena.c
@@ -1,6 +1,5 @@
|
||||
#include "base.h"
|
||||
|
||||
#include "arena.h"
|
||||
#include "base.h"
|
||||
|
||||
/* ============================================================
|
||||
Helper functions
|
||||
@@ -132,9 +131,6 @@ mem_arena *arena_create(arena_params *params) { // mk create
|
||||
|
||||
u32 pagesize = arena_pagesize();
|
||||
|
||||
u64 align = params->align ? params->align : ARENA_ALIGN;
|
||||
ASSERT((align & (align - 1)) == 0);
|
||||
|
||||
u64 reserve_size = ALIGN_UP_POW2(params->reserve_size, pagesize);
|
||||
u64 commit_size =
|
||||
params->commit_size ? ALIGN_UP_POW2(params->commit_size, pagesize) : 0;
|
||||
@@ -181,7 +177,7 @@ mem_arena *arena_create(arena_params *params) { // mk create
|
||||
arena->commit_size = commit_size;
|
||||
arena->commit_pos = commit_size;
|
||||
|
||||
arena->align = align;
|
||||
arena->align = params->align;
|
||||
arena->push_size = 0;
|
||||
|
||||
arena->allow_free_list = params->allow_free_list;
|
||||
@@ -360,7 +356,8 @@ void *arena_push(mem_arena **arena_ptr, u64 size, bool zero) { // mk push
|
||||
u64 local_pre = ALIGN_UP_POW2(local_pos, selected->align);
|
||||
u64 local_post = local_pre + size;
|
||||
|
||||
if (local_post > selected->reserve_size) {
|
||||
if (local_post > selected->reserve_size -
|
||||
ALIGN_UP_POW2(sizeof(mem_arena), selected->align)) {
|
||||
|
||||
if (arena->allow_free_list && arena->push_size == 0) {
|
||||
u64 tail_start = selected->pos;
|
||||
@@ -605,8 +602,8 @@ void *arena_swapback_pop(mem_arena **arena_ptr, u64 index) { // mk swapback
|
||||
mem_arena *owner = arena_block_from_index(arena, index);
|
||||
|
||||
if (!owner) {
|
||||
fprintf(stderr, "ERROR: Swapback pop failed, index out of range");
|
||||
return NULL;
|
||||
fprintf(stderr, "ERROR: Swapback pop failed, index out of range");
|
||||
return NULL;
|
||||
}
|
||||
u8 *owner_base = (u8 *)owner + ALIGN_UP_POW2(sizeof(mem_arena), owner->align);
|
||||
u8 *arena_base = (u8 *)arena + ALIGN_UP_POW2(sizeof(mem_arena), arena->align);
|
||||
|
||||
Reference in New Issue
Block a user