aboutsummaryrefslogtreecommitdiff
path: root/src/compiler.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-02-27 23:04:36 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit0ed62b9337c64a91481afd91f9e5706a36eca7b5 (patch)
treee85efe1d6acc8b661a5c63974ec067007dc4ad11 /src/compiler.c
parent76d85a10f6cda93eba29dad5372e8160af7289c8 (diff)
Fix scoped allocator alloc bug, do all processing in non-main threads. Main only join
Diffstat (limited to 'src/compiler.c')
-rw-r--r--src/compiler.c20
1 files changed, 5 insertions, 15 deletions
diff --git a/src/compiler.c b/src/compiler.c
index fba18d3..6f1c954 100644
--- a/src/compiler.c
+++ b/src/compiler.c
@@ -34,8 +34,6 @@ int amal_compiler_init(amal_compiler *self) {
amal_log_info("Environment variable THREADS contains invalid number for threads. THREADS has to be at least 1.");
return AMAL_COMPILER_ERR;
}
- /* Exclude thread count because we also use the main thread */
- --self->usable_thread_count;
am_memset(&self->allocator, 0, sizeof(self->allocator));
am_memset(&self->main_thread_allocator, 0, sizeof(self->main_thread_allocator));
@@ -140,7 +138,6 @@ static CHECK_RESULT int amal_compiler_load_file_select_thread(amal_compiler *sel
thread_user_data = NULL;
*thread_selected = NULL;
result = AMAL_COMPILER_ERR;
- assert(amal_thread_is_main());
cleanup_if_error(amal_mutex_lock(&self->mutex, "amal_compiler_load_file_select_thread"));
for(i = 0; i < self->usable_thread_count; ++i) {
@@ -172,16 +169,8 @@ static CHECK_RESULT int amal_compiler_load_file_join_threads(amal_compiler *self
ParserThreadData *parser_thread_data;
result = AMAL_COMPILER_ERR;
(void)_;
-
- while(self->queued_files.size > 0) {
- BufferView filepath;
- cleanup_if_error(amal_mutex_lock(&self->mutex, "amal_compiler_load_file_join_threads remaining files"));
- _ = buffer_pop(&self->queued_files, &filepath, sizeof(filepath));
- amal_mutex_tryunlock(&self->mutex);
- if(filepath.data)
- return_if_error(amal_compiler_load_first_this_thread(self, filepath, &self->main_thread_allocator));
- }
-
+ assert(amal_thread_is_main());
+
for(i = 0; i < self->usable_thread_count; ++i) {
cleanup_if_error(amal_mutex_lock(&self->mutex, "amal_compiler_load_file_join_threads, waiting for workers"));
parser_thread_data = &self->threads[i];
@@ -200,6 +189,8 @@ int amal_compiler_load_file(amal_compiler *self, BufferView filepath) {
ParserThreadData *parser_thread_data;
result = AMAL_COMPILER_ERR;
+ return_if_error(amal_compiler_load_file_select_thread(self, filepath, &parser_thread_data));
+
/*
amal_compiler_load_file is called by the user for the first file to compile
but also called by the parser when it sees @import
@@ -207,11 +198,10 @@ int amal_compiler_load_file(amal_compiler *self, BufferView filepath) {
if(!self->started) {
self->started = bool_true;
/*amal_log_info("Parsing %.*s using %d thread(s)", (int)filepath.size, filepath.data, self->usable_thread_count);*/
- return_if_error(amal_compiler_load_first_this_thread(self, filepath, &self->main_thread_allocator));
+ /*return_if_error(amal_compiler_load_first_this_thread(self, filepath, &self->main_thread_allocator));*/
return amal_compiler_load_file_join_threads(self);
}
- return_if_error(amal_compiler_load_file_select_thread(self, filepath, &parser_thread_data));
if(parser_thread_data)
return AMAL_COMPILER_OK;