aboutsummaryrefslogtreecommitdiff
path: root/src/check_decl.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-07-10 21:29:49 +0100
committergingerBill <bill@gingerbill.org>2021-07-10 21:29:49 +0100
commited8a6f872dbcd8b195940dec40a0d86d59f11eaa (patch)
treebbf4d7fc301a432583f8f2121742a83c1d4cc6af /src/check_decl.cpp
parent0a61d4bf2b2d6e8c8d0c92410f6dcfd2b6046f86 (diff)
Move things around for sanity checking for multithread preparation
Diffstat (limited to 'src/check_decl.cpp')
-rw-r--r--src/check_decl.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/check_decl.cpp b/src/check_decl.cpp
index 84817e9d8..d7f04ca5c 100644
--- a/src/check_decl.cpp
+++ b/src/check_decl.cpp
@@ -809,9 +809,7 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
if (ac.deferred_procedure.entity != nullptr) {
e->Procedure.deferred_procedure = ac.deferred_procedure;
- gb_mutex_lock(&ctx->checker->procs_with_deferred_to_check_mutex);
- array_add(&ctx->checker->procs_with_deferred_to_check, e);
- gb_mutex_unlock(&ctx->checker->procs_with_deferred_to_check_mutex);
+ mpmc_enqueue(&ctx->checker->procs_with_deferred_to_check, e);
}
if (is_foreign) {
@@ -824,6 +822,8 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
init_entity_foreign_library(ctx, e);
+ gb_mutex_lock(&ctx->info->foreign_mutex);
+
auto *fp = &ctx->info->foreigns;
StringHashKey key = string_hash_string(name);
Entity **found = string_map_get(fp, key);
@@ -850,12 +850,16 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
} else {
string_map_set(fp, key, e);
}
+
+ gb_mutex_unlock(&ctx->info->foreign_mutex);
} else {
String name = e->token.string;
if (e->Procedure.link_name.len > 0) {
name = e->Procedure.link_name;
}
if (e->Procedure.link_name.len > 0 || is_export) {
+ gb_mutex_lock(&ctx->info->foreign_mutex);
+
auto *fp = &ctx->info->foreigns;
StringHashKey key = string_hash_string(name);
Entity **found = string_map_get(fp, key);
@@ -872,6 +876,8 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
} else {
string_map_set(fp, key, e);
}
+
+ gb_mutex_unlock(&ctx->info->foreign_mutex);
}
}
}
@@ -896,7 +902,9 @@ void check_global_variable_decl(CheckerContext *ctx, Entity *&e, Ast *type_expr,
}
if (ac.require_declaration) {
+ gb_mutex_lock(&ctx->info->entity_mutex);
array_add(&ctx->info->required_global_variables, e);
+ gb_mutex_unlock(&ctx->info->entity_mutex);
}
@@ -1320,6 +1328,8 @@ void check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *decl, Type *ty
if (ps->flags & (ScopeFlag_File & ScopeFlag_Pkg & ScopeFlag_Global)) {
return;
} else {
+ gb_mutex_lock(&ctx->info->deps_mutex);
+
// NOTE(bill): Add the dependencies from the procedure literal (lambda)
// But only at the procedure level
for_array(i, decl->deps.entries) {
@@ -1330,6 +1340,8 @@ void check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *decl, Type *ty
Type *t = decl->type_info_deps.entries[i].ptr;
ptr_set_add(&decl->parent->type_info_deps, t);
}
+
+ gb_mutex_unlock(&ctx->info->deps_mutex);
}
}
}