From 385e2b95cb635976aded7368c6f7ac29585b38e7 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 12 Mar 2019 19:32:15 +0100 Subject: Fix race in amal_compiler_load_file --- src/compiler.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/compiler.c b/src/compiler.c index dc703f8..fbdeb94 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -335,22 +335,30 @@ static CHECK_RESULT int amal_compiler_dispatch_generic(amal_compiler *self, Thre return amal_compiler_load_file_join_threads(self); } +/* +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 +*/ int amal_compiler_load_file(amal_compiler *self, BufferView filepath) { int result; ParserThreadData *parser_thread_data; ThreadWorkData thread_work_data; + bool main_job; + result = AMAL_COMPILER_ERR; thread_work_data.type = THREAD_WORK_PARSE; thread_work_data.value.filepath = filepath; + main_job = bool_false; - return_if_error(amal_compiler_select_thread_for_work(self, thread_work_data, &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 - */ + /* The first time we get here, this will run single-threaded so this part doesn't need mutex */ if(!self->started) { self->started = bool_true; + main_job = bool_true; + } + + return_if_error(amal_compiler_select_thread_for_work(self, thread_work_data, &parser_thread_data)); + + if(main_job) { /*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_file_join_threads(self)); -- cgit v1.2.3