aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2021-08-26 21:44:02 +0100
committerGitHub <noreply@github.com>2021-08-26 21:44:02 +0100
commitcdd35607023a333ae096f5a7e1437082a437ff04 (patch)
treef62394981d7554acdddac3d3e68c60daa7af23a8 /src/main.cpp
parente45aa68c14149cc4ebcc352e3fe4631c642f33f3 (diff)
parent6d49df1d87fb1d74f00977dee3a3ce42c46c1eee (diff)
Merge pull request #1103 from odin-lang/new-thread-pool
Improved Thread Pool implementation for the Compiler
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index dab1257bd..f94b6bd4f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,6 +7,20 @@
#include "exact_value.cpp"
#include "build_settings.cpp"
+gb_global ThreadPool global_thread_pool;
+void init_global_thread_pool(void) {
+ 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
+ thread_pool_init(&global_thread_pool, permanent_allocator(), worker_count, "ThreadPoolWorker");
+}
+bool global_thread_pool_add_task(WorkerTaskProc *proc, void *data) {
+ return thread_pool_add_task(&global_thread_pool, proc, data);
+}
+void global_thread_pool_wait(void) {
+ thread_pool_wait(&global_thread_pool);
+}
+
+
void debugf(char const *fmt, ...) {
if (build_context.show_debug_messages) {
gb_printf_err("[DEBUG] ");
@@ -2160,6 +2174,9 @@ int main(int arg_count, char const **arg_ptr) {
// return 1;
// }
+ init_global_thread_pool();
+ defer (thread_pool_destroy(&global_thread_pool));
+
init_universal();
// TODO(bill): prevent compiling without a linker