diff options
| author | gingerBill <bill@gingerbill.org> | 2023-01-02 20:38:37 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-01-02 20:38:37 +0000 |
| commit | 09c26e6be006cb285aed4b0780bee368516fd272 (patch) | |
| tree | d3ed2b6fadd65fa19c8a7ae79a7eeaae5ed4a690 | |
| parent | d2ec2d1606013eb28f608d2ecaec3a654ec3598f (diff) | |
Narrow type info mutex usage
| -rw-r--r-- | src/checker.cpp | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/src/checker.cpp b/src/checker.cpp index daebe0d31..dc6a49bcf 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -1731,10 +1731,7 @@ gb_internal void add_type_info_type(CheckerContext *c, Type *t) { if (build_context.disallow_rtti) { return; } - - mutex_lock(&c->info->type_info_mutex); add_type_info_type_internal(c, t); - mutex_unlock(&c->info->type_info_mutex); } gb_internal void add_type_info_type_internal(CheckerContext *c, Type *t) { @@ -1751,33 +1748,35 @@ gb_internal void add_type_info_type_internal(CheckerContext *c, Type *t) { add_type_info_dependency(c->info, c->decl, t); - auto found = map_get(&c->info->type_info_map, t); - if (found != nullptr) { - // Types have already been added - return; - } + MUTEX_GUARD_BLOCK(&c->info->type_info_mutex) { + auto found = map_get(&c->info->type_info_map, t); + if (found != nullptr) { + // Types have already been added + return; + } - bool prev = false; - isize ti_index = -1; - for (auto const &e : c->info->type_info_map) { - if (are_types_identical_unique_tuples(t, e.key)) { - // Duplicate entry - ti_index = e.value; - prev = true; - break; + bool prev = false; + isize ti_index = -1; + for (auto const &e : c->info->type_info_map) { + if (are_types_identical_unique_tuples(t, e.key)) { + // Duplicate entry + ti_index = e.value; + prev = true; + break; + } } - } - if (ti_index < 0) { - // Unique entry - // NOTE(bill): map entries grow linearly and in order - ti_index = c->info->type_info_types.count; - array_add(&c->info->type_info_types, t); - } - map_set(&c->checker->info.type_info_map, t, ti_index); + if (ti_index < 0) { + // Unique entry + // NOTE(bill): map entries grow linearly and in order + ti_index = c->info->type_info_types.count; + array_add(&c->info->type_info_types, t); + } + map_set(&c->checker->info.type_info_map, t, ti_index); - if (prev) { - // NOTE(bill): If a previous one exists already, no need to continue - return; + if (prev) { + // NOTE(bill): If a previous one exists already, no need to continue + return; + } } // Add nested types |