aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2025-09-10 21:00:43 +0100
committergingerBill <gingerBill@users.noreply.github.com>2025-09-10 21:00:43 +0100
commit549edcc0f90d632587c427e5d4189721323bd4a8 (patch)
treefa683b18b3a392ce2b3ec881c1c940c9e972c2af
parent34e3d3078057fdf22c2f91847096e0a3e098fa82 (diff)
Use a `RwMutex` instead of `BlockingMutex`
-rw-r--r--src/check_expr.cpp5
-rw-r--r--src/check_type.cpp4
-rw-r--r--src/checker.hpp2
-rw-r--r--src/llvm_backend_expr.cpp5
-rw-r--r--src/types.cpp13
5 files changed, 13 insertions, 16 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index 86b4f3aee..abfd11485 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -5101,7 +5101,6 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v
ast_node(fv, FieldValue, elem);
String name = fv->field->Ident.token.string;
Selection sub_sel = lookup_field(node->tav.type, name, false);
- defer (array_free(&sub_sel.index));
if (sub_sel.index.count > 0 &&
sub_sel.index[0] == index) {
value = fv->value->tav.value;
@@ -7885,9 +7884,9 @@ 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);
+ rw_mutex_shared_lock(&found_gen_types->mutex);
Entity *found_entity = find_polymorphic_record_entity(found_gen_types, param_count, ordered_operands);
- mutex_unlock(&found_gen_types->mutex);
+ rw_mutex_shared_unlock(&found_gen_types->mutex);
if (found_entity) {
operand->mode = Addressing_Type;
diff --git a/src/check_type.cpp b/src/check_type.cpp
index aec416921..71db34afa 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -321,8 +321,8 @@ gb_internal void add_polymorphic_record_entity(CheckerContext *ctx, Ast *node, T
e->TypeName.objc_metadata = original_type->Named.type_name->TypeName.objc_metadata;
auto *found_gen_types = ensure_polymorphic_record_entity_has_gen_types(ctx, original_type);
- mutex_lock(&found_gen_types->mutex);
- defer (mutex_unlock(&found_gen_types->mutex));
+ rw_mutex_lock(&found_gen_types->mutex);
+ defer (rw_mutex_unlock(&found_gen_types->mutex));
for (Entity *prev : found_gen_types->types) {
if (prev == e) {
diff --git a/src/checker.hpp b/src/checker.hpp
index ddf713dad..968988962 100644
--- a/src/checker.hpp
+++ b/src/checker.hpp
@@ -417,7 +417,7 @@ struct GenProcsData {
struct GenTypesData {
Array<Entity *> types;
- BlockingMutex mutex;
+ RwMutex mutex;
};
struct Defineable {
diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp
index ebc3ec158..cff91813e 100644
--- a/src/llvm_backend_expr.cpp
+++ b/src/llvm_backend_expr.cpp
@@ -2563,10 +2563,11 @@ gb_internal lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
Type *dt = t;
+ TEMPORARY_ALLOCATOR_GUARD();
+
GB_ASSERT(is_type_struct(st) || is_type_raw_union(st));
Selection sel = {};
- sel.index.allocator = heap_allocator();
- defer (array_free(&sel.index));
+ sel.index.allocator = temporary_allocator();
if (lookup_subtype_polymorphic_selection(t, src_type, &sel)) {
if (sel.entity == nullptr) {
GB_PANIC("invalid subtype cast %s -> ", type_to_string(src_type), type_to_string(t));
diff --git a/src/types.cpp b/src/types.cpp
index 3ccc74996..4515b2c60 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -435,11 +435,8 @@ gb_internal Selection make_selection(Entity *entity, Array<i32> index, bool indi
}
gb_internal void selection_add_index(Selection *s, isize index) {
- // IMPORTANT NOTE(bill): this requires a stretchy buffer/dynamic array so it requires some form
- // of heap allocation
- // TODO(bill): Find a way to use a backing buffer for initial use as the general case is probably .count<3
if (s->index.data == nullptr) {
- array_init(&s->index, heap_allocator());
+ array_init(&s->index, permanent_allocator());
}
array_add(&s->index, cast(i32)index);
}
@@ -447,7 +444,7 @@ gb_internal void selection_add_index(Selection *s, isize index) {
gb_internal Selection selection_combine(Selection const &lhs, Selection const &rhs) {
Selection new_sel = lhs;
new_sel.indirect = lhs.indirect || rhs.indirect;
- new_sel.index = array_make<i32>(heap_allocator(), lhs.index.count+rhs.index.count);
+ new_sel.index = array_make<i32>(permanent_allocator(), lhs.index.count+rhs.index.count);
array_copy(&new_sel.index, lhs.index, 0);
array_copy(&new_sel.index, rhs.index, lhs.index.count);
return new_sel;
@@ -3958,7 +3955,7 @@ gb_internal i64 type_size_of(Type *t) {
TypePath path{};
type_path_init(&path);
{
- MUTEX_GUARD(&g_type_mutex);
+ // MUTEX_GUARD(&g_type_mutex);
size = type_size_of_internal(t, &path);
t->cached_size.store(size);
}
@@ -3978,7 +3975,7 @@ gb_internal i64 type_align_of(Type *t) {
TypePath path{};
type_path_init(&path);
{
- MUTEX_GUARD(&g_type_mutex);
+ // MUTEX_GUARD(&g_type_mutex);
t->cached_align.store(type_align_of_internal(t, &path));
}
type_path_free(&path);
@@ -4704,7 +4701,7 @@ gb_internal Type *alloc_type_tuple_from_field_types(Type **field_types, isize fi
}
Type *t = alloc_type_tuple();
- t->Tuple.variables = slice_make<Entity *>(heap_allocator(), field_count);
+ t->Tuple.variables = slice_make<Entity *>(permanent_allocator(), field_count);
Scope *scope = nullptr;
for_array(i, t->Tuple.variables) {