More explicit uses of mutexes

This commit is contained in:
gingerBill
2023-01-02 23:56:37 +00:00
parent e10fe91eba
commit 670274ad8f

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());
if (found) {
gen_procs = *found;
MUTEX_GUARD(&gen_procs->mutex);
mutex_lock(&gen_procs->mutex); // @local-mutex
for (Entity *other : gen_procs->procs) {
Type *pt = base_type(other->type);
if (are_types_identical(pt, final_proc_type)) {
mutex_unlock(&gen_procs->mutex); // @local-mutex
// @@GPM ////////////////////////////
mutex_unlock(&info->gen_procs_mutex);
/////////////////////////////////////
@@ -456,6 +457,7 @@ gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, E
return true;
}
}
mutex_unlock(&gen_procs->mutex); // @local-mutex
} else {
gen_procs = gb_alloc_item(permanent_allocator(), GenProcsData);
gen_procs->procs.allocator = heap_allocator();
@@ -481,10 +483,12 @@ gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, E
return false;
}
MUTEX_GUARD(&gen_procs->mutex);
mutex_lock(&gen_procs->mutex); // @local-mutex
for (Entity *other : gen_procs->procs) {
Type *pt = base_type(other->type);
if (are_types_identical(pt, final_proc_type)) {
mutex_unlock(&gen_procs->mutex); // @local-mutex
if (poly_proc_data) {
poly_proc_data->gen_entity = other;
}
@@ -507,6 +511,7 @@ gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, E
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);
}
mutex_unlock(&gen_procs->mutex); // @local-mutex
ProcInfo *proc_info = gb_alloc_item(permanent_allocator(), ProcInfo);
proc_info->file = file;