Add mutex for lb_handle_objc_find_or_register_selector

This commit is contained in:
gingerBill
2025-04-02 18:23:08 +01:00
parent cc61fdd90e
commit d0dd1b2d80
2 changed files with 8 additions and 0 deletions

View File

@@ -165,6 +165,7 @@ struct lbModule {
PtrMap<u64/*type hash*/, LLVMTypeRef> func_raw_types; // mutex: func_raw_types_mutex
RecursiveMutex types_mutex;
RecursiveMutex func_raw_types_mutex;
RecursiveMutex objc_selectors_mutex;
i32 internal_type_level;
RwMutex values_mutex;

View File

@@ -2096,7 +2096,11 @@ gb_internal void lb_set_wasm_export_attributes(LLVMValueRef value, String export
gb_internal lbAddr lb_handle_objc_find_or_register_selector(lbProcedure *p, String const &name) {
mutex_lock(&p->module->objc_selectors_mutex);
defer (mutex_unlock(&p->module->objc_selectors_mutex));
lbObjcRef *found = string_map_get(&p->module->objc_selectors, name);
if (found) {
return found->local_module_addr;
}
@@ -2118,7 +2122,10 @@ gb_internal lbAddr lb_handle_objc_find_or_register_selector(lbProcedure *p, Stri
lbAddr default_addr = lb_add_global_generated_with_name(default_module, t_objc_SEL, {},
make_string(cast(u8 const *)global_name, gb_string_length(global_name)),
&entity);
mutex_lock(&default_module->objc_selectors_mutex);
string_map_set(&default_module->objc_selectors, name, lbObjcRef{entity, default_addr});
mutex_unlock(&default_module->objc_selectors_mutex);
}
lbValue ptr = lb_find_value_from_entity(p->module, entity);