mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Minimize the parapoly mutex usage a bit
This commit is contained in:
+44
-54
@@ -434,20 +434,22 @@ gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, E
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GenProcsData *found_gen_procs = nullptr;
|
GenProcsData *gen_procs = nullptr;
|
||||||
|
|
||||||
// @@GPM
|
// @@GPM //////////////////////////
|
||||||
mutex_lock(&info->gen_procs_mutex);
|
mutex_lock(&info->gen_procs_mutex);
|
||||||
|
///////////////////////////////////
|
||||||
|
|
||||||
found_gen_procs = 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) {
|
gen_procs = *found;
|
||||||
MUTEX_GUARD(&found_gen_procs->mutex);
|
MUTEX_GUARD(&gen_procs->mutex);
|
||||||
for (Entity *other : found_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)) {
|
||||||
// @@GPM
|
// @@GPM ////////////////////////////
|
||||||
mutex_unlock(&info->gen_procs_mutex);
|
mutex_unlock(&info->gen_procs_mutex);
|
||||||
|
/////////////////////////////////////
|
||||||
|
|
||||||
if (poly_proc_data) {
|
if (poly_proc_data) {
|
||||||
poly_proc_data->gen_entity = other;
|
poly_proc_data->gen_entity = other;
|
||||||
@@ -455,6 +457,10 @@ gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, E
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
gen_procs = gb_alloc_item(permanent_allocator(), GenProcsData);
|
||||||
|
gen_procs->procs.allocator = heap_allocator();
|
||||||
|
map_set(&info->gen_procs, base_entity->identifier.load(), gen_procs);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -469,50 +475,43 @@ gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, E
|
|||||||
// LEAK TODO(bill): Cloning this AST may be leaky
|
// LEAK TODO(bill): Cloning this AST may be leaky
|
||||||
Ast *cloned_proc_type_node = clone_ast(pt->node);
|
Ast *cloned_proc_type_node = clone_ast(pt->node);
|
||||||
success = check_procedure_type(&nctx, final_proc_type, cloned_proc_type_node, &operands);
|
success = check_procedure_type(&nctx, final_proc_type, cloned_proc_type_node, &operands);
|
||||||
|
|
||||||
|
// @@GPM ////////////////////////////
|
||||||
|
mutex_unlock(&info->gen_procs_mutex);
|
||||||
|
/////////////////////////////////////
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
// @@GPM
|
|
||||||
mutex_unlock(&info->gen_procs_mutex);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found_gen_procs) {
|
MUTEX_GUARD(&gen_procs->mutex);
|
||||||
MUTEX_GUARD(&found_gen_procs->mutex);
|
for (Entity *other : gen_procs->procs) {
|
||||||
for (Entity *other : found_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)) {
|
if (poly_proc_data) {
|
||||||
// @@GPM
|
poly_proc_data->gen_entity = other;
|
||||||
mutex_unlock(&info->gen_procs_mutex);
|
|
||||||
|
|
||||||
if (poly_proc_data) {
|
|
||||||
poly_proc_data->gen_entity = other;
|
|
||||||
}
|
|
||||||
|
|
||||||
DeclInfo *decl = other->decl_info;
|
|
||||||
if (decl->proc_checked_state != ProcCheckedState_Checked) {
|
|
||||||
ProcInfo *proc_info = gb_alloc_item(permanent_allocator(), ProcInfo);
|
|
||||||
proc_info->file = other->file;
|
|
||||||
proc_info->token = other->token;
|
|
||||||
proc_info->decl = decl;
|
|
||||||
proc_info->type = other->type;
|
|
||||||
proc_info->body = decl->proc_lit->ProcLit.body;
|
|
||||||
proc_info->tags = other->Procedure.tags;;
|
|
||||||
proc_info->generated_from_polymorphic = true;
|
|
||||||
proc_info->poly_def_node = poly_def_node;
|
|
||||||
|
|
||||||
check_procedure_later(nctx.checker, proc_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeclInfo *decl = other->decl_info;
|
||||||
|
if (decl->proc_checked_state != ProcCheckedState_Checked) {
|
||||||
|
ProcInfo *proc_info = gb_alloc_item(permanent_allocator(), ProcInfo);
|
||||||
|
proc_info->file = other->file;
|
||||||
|
proc_info->token = other->token;
|
||||||
|
proc_info->decl = decl;
|
||||||
|
proc_info->type = other->type;
|
||||||
|
proc_info->body = decl->proc_lit->ProcLit.body;
|
||||||
|
proc_info->tags = other->Procedure.tags;;
|
||||||
|
proc_info->generated_from_polymorphic = true;
|
||||||
|
proc_info->poly_def_node = poly_def_node;
|
||||||
|
|
||||||
|
check_procedure_later(nctx.checker, proc_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found_gen_procs) {
|
|
||||||
// @@GPM
|
|
||||||
mutex_unlock(&info->gen_procs_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Ast *proc_lit = clone_ast(old_decl->proc_lit);
|
Ast *proc_lit = clone_ast(old_decl->proc_lit);
|
||||||
ast_node(pl, ProcLit, proc_lit);
|
ast_node(pl, ProcLit, proc_lit);
|
||||||
@@ -570,17 +569,8 @@ gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, E
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found_gen_procs) {
|
MUTEX_GUARD_BLOCK(&gen_procs->mutex) {
|
||||||
MUTEX_GUARD(&found_gen_procs->mutex);
|
array_add(&gen_procs->procs, entity);
|
||||||
array_add(&found_gen_procs->procs, entity);
|
|
||||||
} else {
|
|
||||||
GenProcsData gen_proc_data = {};
|
|
||||||
gen_proc_data.procs = array_make<Entity *>(heap_allocator());
|
|
||||||
array_add(&gen_proc_data.procs, entity);
|
|
||||||
map_set(&info->gen_procs, base_entity->identifier.load(), gen_proc_data);
|
|
||||||
|
|
||||||
// @@GPM
|
|
||||||
mutex_unlock(&info->gen_procs_mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcInfo *proc_info = gb_alloc_item(permanent_allocator(), ProcInfo);
|
ProcInfo *proc_info = gb_alloc_item(permanent_allocator(), ProcInfo);
|
||||||
|
|||||||
+1
-1
@@ -369,7 +369,7 @@ struct CheckerInfo {
|
|||||||
|
|
||||||
RecursiveMutex gen_procs_mutex;
|
RecursiveMutex gen_procs_mutex;
|
||||||
RecursiveMutex gen_types_mutex;
|
RecursiveMutex gen_types_mutex;
|
||||||
PtrMap<Ast *, GenProcsData > gen_procs; // Key: Ast * | Identifier -> Entity
|
PtrMap<Ast *, GenProcsData *> gen_procs; // Key: Ast * | Identifier -> Entity
|
||||||
PtrMap<Type *, Array<Entity *> > gen_types;
|
PtrMap<Type *, Array<Entity *> > gen_types;
|
||||||
|
|
||||||
BlockingMutex type_info_mutex; // NOT recursive
|
BlockingMutex type_info_mutex; // NOT recursive
|
||||||
|
|||||||
@@ -57,8 +57,9 @@ gb_internal void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd)
|
|||||||
if (pl->body != nullptr) {
|
if (pl->body != nullptr) {
|
||||||
auto *found = map_get(&info->gen_procs, ident);
|
auto *found = map_get(&info->gen_procs, ident);
|
||||||
if (found) {
|
if (found) {
|
||||||
MUTEX_GUARD(&found->mutex);
|
GenProcsData *gpd = *found;
|
||||||
for (Entity *e : found->procs) {
|
MUTEX_GUARD(&gpd->mutex);
|
||||||
|
for (Entity *e : gpd->procs) {
|
||||||
if (!ptr_set_exists(min_dep_set, e)) {
|
if (!ptr_set_exists(min_dep_set, e)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user