From 10cc9cf6614c33072f26d0e1901ce2f8e5a2c91c Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Tue, 1 Aug 2017 14:24:40 +0100 Subject: Add mutexes to string buffer allocator uses --- src/parser.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index 2667289eb..470bee3d0 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -79,8 +79,6 @@ struct Parser { String init_fullpath; Array files; Array imports; - isize curr_import_index; - gbAtomic32 import_index; isize total_token_count; isize total_line_count; gbMutex file_add_mutex; @@ -4921,7 +4919,7 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Arrayrelpath.string; String file_str = id->relpath.string; - gbAllocator allocator = heap_allocator(); // TODO(bill): Change this allocator + gbAllocator a = heap_allocator(); // TODO(bill): Change this allocator String import_file = {}; String rel_path = {}; @@ -4936,15 +4934,13 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Arrayfile_decl_mutex); defer (gb_mutex_unlock(&p->file_decl_mutex)); - rel_path = get_fullpath_relative(allocator, base_dir, file_str); + rel_path = get_fullpath_relative(a, base_dir, file_str); import_file = rel_path; if (!gb_file_exists(cast(char *)rel_path.text)) { // NOTE(bill): This should be null terminated - String abs_path = get_fullpath_core(allocator, file_str); + String abs_path = get_fullpath_core(a, file_str); if (gb_file_exists(cast(char *)abs_path.text)) { import_file = abs_path; } @@ -5105,6 +5101,7 @@ ParseFileError parse_files(Parser *p, String init_filename) { gbThread *t = &worker_threads[i]; gb_thread_init(t); } + isize curr_import_index = 0; // NOTE(bill): Make sure that these are in parsed in this order for (isize i = 0; i < shared_file_count; i++) { @@ -5112,7 +5109,7 @@ ParseFileError parse_files(Parser *p, String init_filename) { if (err != ParseFile_None) { return err; } - p->curr_import_index++; + curr_import_index++; } for (;;) { @@ -5121,19 +5118,20 @@ ParseFileError parse_files(Parser *p, String init_filename) { gbThread *t = &worker_threads[i]; if (gb_thread_is_running(t)) { are_any_alive = true; - } else if (p->curr_import_index < p->imports.count) { - if (t->return_value != 0) { + } else if (curr_import_index < p->imports.count) { + auto err = cast(ParseFileError)t->return_value; + if (err != ParseFile_None) { for_array(i, worker_threads) { gb_thread_destroy(&worker_threads[i]); } - return cast(ParseFileError)t->return_value; + return err; } - t->user_index = p->curr_import_index++; + t->user_index = curr_import_index++; gb_thread_start(t, parse_worker_file_proc, p); are_any_alive = true; } } - if (!are_any_alive && p->curr_import_index >= p->imports.count) { + if (!are_any_alive && curr_import_index >= p->imports.count) { break; } } -- cgit v1.2.3