Browse Source

Replace `RecursiveMutex` with a `BlockingMutex`

gingerBill 2 years ago
parent
commit
65c0255e7e
3 changed files with 14 additions and 13 deletions
  1. 1 1
      src/llvm_backend.hpp
  2. 2 3
      src/llvm_backend_debug.cpp
  3. 11 9
      src/llvm_backend_general.cpp

+ 1 - 1
src/llvm_backend.hpp

@@ -143,7 +143,7 @@ struct lbModule {
 	PtrMap<void *, lbStructFieldRemapping> struct_field_remapping; // Key: LLVMTypeRef or Type *
 	PtrMap<void *, lbStructFieldRemapping> struct_field_remapping; // Key: LLVMTypeRef or Type *
 	i32 internal_type_level;
 	i32 internal_type_level;
 
 
-	RecursiveMutex values_mutex;
+	BlockingMutex values_mutex;
 
 
 	PtrMap<Entity *, lbValue> values;           
 	PtrMap<Entity *, lbValue> values;           
 	PtrMap<Entity *, lbAddr>  soa_values;       
 	PtrMap<Entity *, lbAddr>  soa_values;       

+ 2 - 3
src/llvm_backend_debug.cpp

@@ -495,15 +495,14 @@ gb_internal LLVMMetadataRef lb_get_base_scope_metadata(lbModule *m, Scope *scope
 }
 }
 
 
 gb_internal LLVMMetadataRef lb_debug_type(lbModule *m, Type *type) {
 gb_internal LLVMMetadataRef lb_debug_type(lbModule *m, Type *type) {
-	mutex_lock(&m->debug_values_mutex);
-	defer (mutex_unlock(&m->debug_values_mutex));
-
 	GB_ASSERT(type != nullptr);
 	GB_ASSERT(type != nullptr);
 	LLVMMetadataRef found = lb_get_llvm_metadata(m, type);
 	LLVMMetadataRef found = lb_get_llvm_metadata(m, type);
 	if (found != nullptr) {
 	if (found != nullptr) {
 		return found;
 		return found;
 	}
 	}
 
 
+	MUTEX_GUARD(&m->debug_values_mutex);
+
 	if (type->kind == Type_Named) {
 	if (type->kind == Type_Named) {
 		LLVMMetadataRef file = nullptr;
 		LLVMMetadataRef file = nullptr;
 		unsigned line = 0;
 		unsigned line = 0;

+ 11 - 9
src/llvm_backend_general.cpp

@@ -2547,11 +2547,14 @@ gb_internal lbValue lb_find_ident(lbProcedure *p, lbModule *m, Entity *e, Ast *e
 			return *found;
 			return *found;
 		}
 		}
 	}
 	}
+
+	lbValue *found = nullptr;
 	mutex_lock(&m->values_mutex);
 	mutex_lock(&m->values_mutex);
-	defer (mutex_unlock(&m->values_mutex));
+	found = map_get(&m->values, e);
+	mutex_unlock(&m->values_mutex);
 
 
-	auto *found = map_get(&m->values, e);
 	if (found) {
 	if (found) {
+
 		auto v = *found;
 		auto v = *found;
 		// NOTE(bill): This is because pointers are already pointers in LLVM
 		// NOTE(bill): This is because pointers are already pointers in LLVM
 		if (is_type_proc(v.type)) {
 		if (is_type_proc(v.type)) {
@@ -2598,10 +2601,10 @@ gb_internal lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e)
 	e = strip_entity_wrapping(e);
 	e = strip_entity_wrapping(e);
 	GB_ASSERT(e != nullptr);
 	GB_ASSERT(e != nullptr);
 
 
+	lbValue *found = nullptr;
 	mutex_lock(&m->values_mutex);
 	mutex_lock(&m->values_mutex);
-	defer (mutex_unlock(&m->values_mutex));
-
-	auto *found = map_get(&m->values, e);
+	found = map_get(&m->values, e);
+	mutex_unlock(&m->values_mutex);
 	if (found) {
 	if (found) {
 		return *found;
 		return *found;
 	}
 	}
@@ -2698,11 +2701,10 @@ gb_internal lbValue lb_find_value_from_entity(lbModule *m, Entity *e) {
 		return lb_find_procedure_value_from_entity(m, e);
 		return lb_find_procedure_value_from_entity(m, e);
 	}
 	}
 
 
+	lbValue *found = nullptr;
 	mutex_lock(&m->values_mutex);
 	mutex_lock(&m->values_mutex);
-	defer (mutex_unlock(&m->values_mutex));
-
-
-	auto *found = map_get(&m->values, e);
+	found = map_get(&m->values, e);
+	mutex_unlock(&m->values_mutex);
 	if (found) {
 	if (found) {
 		return *found;
 		return *found;
 	}
 	}