More explicit uses of mutexes

This commit is contained in:
gingerBill
2023-01-02 23:56:37 +00:00
parent e10fe91eba
commit 670274ad8f
+9 -4
View File
@@ -442,10 +442,11 @@ gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, E
auto *found = map_get(&info->gen_procs, base_entity->identifier.load()); auto *found = map_get(&info->gen_procs, base_entity->identifier.load());
if (found) { if (found) {
gen_procs = *found; gen_procs = *found;
MUTEX_GUARD(&gen_procs->mutex); mutex_lock(&gen_procs->mutex); // @local-mutex
for (Entity *other : gen_procs->procs) { for (Entity *other : gen_procs->procs) {
Type *pt = base_type(other->type); Type *pt = base_type(other->type);
if (are_types_identical(pt, final_proc_type)) { if (are_types_identical(pt, final_proc_type)) {
mutex_unlock(&gen_procs->mutex); // @local-mutex
// @@GPM //////////////////////////// // @@GPM ////////////////////////////
mutex_unlock(&info->gen_procs_mutex); mutex_unlock(&info->gen_procs_mutex);
///////////////////////////////////// /////////////////////////////////////
@@ -456,6 +457,7 @@ gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, E
return true; return true;
} }
} }
mutex_unlock(&gen_procs->mutex); // @local-mutex
} else { } else {
gen_procs = gb_alloc_item(permanent_allocator(), GenProcsData); gen_procs = gb_alloc_item(permanent_allocator(), GenProcsData);
gen_procs->procs.allocator = heap_allocator(); gen_procs->procs.allocator = heap_allocator();
@@ -481,10 +483,12 @@ gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, E
return false; return false;
} }
MUTEX_GUARD(&gen_procs->mutex); mutex_lock(&gen_procs->mutex); // @local-mutex
for (Entity *other : gen_procs->procs) { for (Entity *other : gen_procs->procs) {
Type *pt = base_type(other->type); Type *pt = base_type(other->type);
if (are_types_identical(pt, final_proc_type)) { if (are_types_identical(pt, final_proc_type)) {
mutex_unlock(&gen_procs->mutex); // @local-mutex
if (poly_proc_data) { if (poly_proc_data) {
poly_proc_data->gen_entity = other; poly_proc_data->gen_entity = other;
} }
@@ -507,6 +511,7 @@ gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, E
return true; return true;
} }
} }
mutex_unlock(&gen_procs->mutex); // @local-mutex
} }
@@ -566,9 +571,9 @@ gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, E
} }
} }
MUTEX_GUARD_BLOCK(&gen_procs->mutex) { mutex_lock(&gen_procs->mutex); // @local-mutex
array_add(&gen_procs->procs, entity); array_add(&gen_procs->procs, entity);
} mutex_unlock(&gen_procs->mutex); // @local-mutex
ProcInfo *proc_info = gb_alloc_item(permanent_allocator(), ProcInfo); ProcInfo *proc_info = gb_alloc_item(permanent_allocator(), ProcInfo);
proc_info->file = file; proc_info->file = file;