From 0edda2bea769303166eaab2965f6cfb8b2bd807c Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 20 Dec 2022 12:46:33 +0000 Subject: Clarify ThreadPool interface; Move `import_mutex` guarding to just the string set --- src/parser.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index 520f123d8..eb006cb24 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -4966,14 +4966,12 @@ gb_internal void parser_add_foreign_file_to_process(Parser *p, AstPackage *pkg, gb_internal AstPackage *try_add_import_path(Parser *p, String const &path, String const &rel_path, TokenPos pos, PackageKind kind = Package_Normal) { String const FILE_EXT = str_lit(".odin"); - mutex_lock(&p->import_mutex); - defer (mutex_unlock(&p->import_mutex)); - - if (string_set_exists(&p->imported_files, path)) { - return nullptr; + MUTEX_GUARD_BLOCK(&p->import_mutex) { + if (string_set_exists(&p->imported_files, path)) { + return nullptr; + } + string_set_add(&p->imported_files, path); } - string_set_add(&p->imported_files, path); - AstPackage *pkg = gb_alloc_item(permanent_allocator(), AstPackage); pkg->kind = kind; @@ -4991,8 +4989,8 @@ gb_internal AstPackage *try_add_import_path(Parser *p, String const &path, Strin fi.is_dir = false; pkg->is_single_file = true; - parser_add_file_to_process(p, pkg, fi, pos); parser_add_package(p, pkg); + parser_add_file_to_process(p, pkg, fi, pos); return pkg; } -- cgit v1.2.3