浏览代码

More thread contention removal

gingerBill 1 天之前
父节点
当前提交
34e3d30780
共有 3 个文件被更改,包括 11 次插入3 次删除
  1. 1 1
      src/check_expr.cpp
  2. 1 1
      src/checker.hpp
  3. 9 1
      src/parser.cpp

+ 1 - 1
src/check_expr.cpp

@@ -7886,8 +7886,8 @@ gb_internal CallArgumentError check_polymorphic_record_type(CheckerContext *c, O
 		GenTypesData *found_gen_types = ensure_polymorphic_record_entity_has_gen_types(c, original_type);
 
 		mutex_lock(&found_gen_types->mutex);
-		defer (mutex_unlock(&found_gen_types->mutex));
 		Entity *found_entity = find_polymorphic_record_entity(found_gen_types, param_count, ordered_operands);
+		mutex_unlock(&found_gen_types->mutex);
 
 		if (found_entity) {
 			operand->mode = Addressing_Type;

+ 1 - 1
src/checker.hpp

@@ -417,7 +417,7 @@ struct GenProcsData {
 
 struct GenTypesData {
 	Array<Entity *> types;
-	RecursiveMutex  mutex;
+	BlockingMutex   mutex;
 };
 
 struct Defineable {

+ 9 - 1
src/parser.cpp

@@ -1,5 +1,7 @@
 #include "parser_pos.cpp"
 
+gb_global std::atomic<bool> g_parsing_done;
+
 gb_internal bool in_vet_packages(AstFile *file) {
 	if (file == nullptr) {
 		return true;
@@ -176,7 +178,11 @@ gb_internal Ast *clone_ast(Ast *node, AstFile *f) {
 		return nullptr;
 	}
 	if (f == nullptr) {
-		f = node->thread_safe_file();
+		if (g_parsing_done.load(std::memory_order_relaxed)) {
+			f = node->file();
+		} else {
+			f = node->thread_safe_file();
+		}
 	}
 	Ast *n = alloc_ast_node(f, node->kind);
 	gb_memmove(n, node, ast_node_size(node->kind));
@@ -6924,6 +6930,8 @@ gb_internal ParseFileError parse_packages(Parser *p, String init_filename) {
 		}
 	}
 
+	g_parsing_done.store(true, std::memory_order_relaxed);
+
 	return ParseFile_None;
 }