diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-03-12 19:32:15 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | 385e2b95cb635976aded7368c6f7ac29585b38e7 (patch) | |
tree | d995b2e432dd611069ea495c7b70cd71021d3515 /src | |
parent | 2e942f12fc94626f884ba38192b530122a5f0e43 (diff) |
Fix race in amal_compiler_load_file
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler.c | 20 |
1 files changed, 14 insertions, 6 deletions
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)); |