aboutsummaryrefslogtreecommitdiff
path: root/src/checker.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-07-13 17:04:08 +0100
committergingerBill <bill@gingerbill.org>2021-07-13 17:04:08 +0100
commit1877965ac37407200b2d8f67f1c2ae474d1e7cbb (patch)
tree9d27d04443bc0a13976e4ff5e190851619d2cfba /src/checker.cpp
parentcec230950466afc11acf96f8d6030ee09bdbc315 (diff)
Short on `-threaded-checker`
Diffstat (limited to 'src/checker.cpp')
-rw-r--r--src/checker.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/checker.cpp b/src/checker.cpp
index 7acaaa7a4..1ec4ed29a 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -4455,11 +4455,29 @@ GB_THREAD_PROC(thread_proc_body) {
}
void check_procedure_bodies(Checker *c) {
-
isize thread_count = gb_max(build_context.thread_count, 1);
isize worker_count = thread_count-1; // NOTE(bill): The main thread will also be used for work
if (!build_context.threaded_checker) {
worker_count = 0;
+
+ auto *q = &c->procs_to_check_queue;
+ ProcInfo *pi = nullptr;
+ while (mpmc_dequeue(q, &pi)) {
+ GB_ASSERT(pi->decl != nullptr);
+ if (pi->decl->parent && pi->decl->parent->entity) {
+ Entity *parent = pi->decl->parent->entity;
+ // NOTE(bill): Only check a nested procedure if its parent's body has been checked first
+ // This is prevent any possible race conditions in evaluation when multithreaded
+ // NOTE(bill): In single threaded mode, this should never happen
+ if (parent->kind == Entity_Procedure && (parent->flags & EntityFlag_ProcBodyChecked) == 0) {
+ mpmc_enqueue(q, pi);
+ continue;
+ }
+ }
+ check_proc_info(c, pi, nullptr, nullptr);
+ total_bodies_checked.fetch_add(1, std::memory_order_relaxed);
+ }
+ return;
}
global_procedure_body_in_worker_queue = true;
@@ -4472,9 +4490,12 @@ void check_procedure_bodies(Checker *c) {
ThreadProcBodyData *data = thread_data + i;
data->checker = c;
data->queue = gb_alloc_item(permanent_allocator(), ProcBodyQueue);
+ // NOTE(bill) 2x the amount assumes on average only 1 nested procedure
+ // TODO(bill): Determine a good heuristic
mpmc_init(data->queue, heap_allocator(), next_pow2_isize(load_count*2));
}
+ // Distibute the work load into multiple queues
for (isize i = 0; i < thread_count; i++) {
ProcBodyQueue *queue = thread_data[i].queue;
for (isize j = 0; j < load_count; j++) {
@@ -4518,6 +4539,11 @@ void check_procedure_bodies(Checker *c) {
gb_thread_destroy(threads+i);
}
+ {
+ isize remaining = c->procs_to_check_queue.count.load(std::memory_order_relaxed);
+ GB_ASSERT(remaining == 0);
+ }
+
// gb_printf_err("Total Procedure Bodies Checked: %td\n", total_bodies_checked.load(std::memory_order_relaxed));
global_procedure_body_in_worker_queue = false;