aboutsummaryrefslogtreecommitdiff
path: root/src/types.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-01-03 18:21:42 +0000
committergingerBill <bill@gingerbill.org>2023-01-03 18:21:42 +0000
commit17fa8cb6ef4424e4c7cff2439e2d52220f440660 (patch)
treeb41c9d90d263173341555e9097dff8ba13919f39 /src/types.cpp
parent855ebceadcc4612a6451f268ab6d6693838ed5f4 (diff)
Add extra mutex to TypePth just in case
Diffstat (limited to 'src/types.cpp')
-rw-r--r--src/types.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/types.cpp b/src/types.cpp
index fa7c1d7f7..ec7adab5a 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -748,6 +748,7 @@ gb_internal i64 type_align_of_internal(Type *t, TypePath *path);
// IMPORTANT TODO(bill): SHould this TypePath code be removed since type cycle checking is handled much earlier on?
struct TypePath {
+ RecursiveMutex mutex;
Array<Entity *> path; // Entity_TypeName;
bool failure;
};
@@ -758,7 +759,9 @@ gb_internal void type_path_init(TypePath *tp) {
}
gb_internal void type_path_free(TypePath *tp) {
+ mutex_lock(&tp->mutex);
array_free(&tp->path);
+ mutex_unlock(&tp->mutex);
}
gb_internal void type_path_print_illegal_cycle(TypePath *tp, isize start_index) {
@@ -787,6 +790,8 @@ gb_internal bool type_path_push(TypePath *tp, Type *t) {
}
Entity *e = t->Named.type_name;
+ mutex_lock(&tp->mutex);
+
for (isize i = 0; i < tp->path.count; i++) {
Entity *p = tp->path[i];
if (p == e) {
@@ -795,12 +800,19 @@ gb_internal bool type_path_push(TypePath *tp, Type *t) {
}
array_add(&tp->path, e);
+
+ mutex_unlock(&tp->mutex);
+
return true;
}
gb_internal void type_path_pop(TypePath *tp) {
- if (tp != nullptr && tp->path.count > 0) {
- array_pop(&tp->path);
+ if (tp != nullptr) {
+ mutex_lock(&tp->mutex);
+ if (tp->path.count > 0) {
+ array_pop(&tp->path);
+ }
+ mutex_unlock(&tp->mutex);
}
}