diff options
| author | gingerBill <bill@gingerbill.org> | 2024-11-26 16:14:13 +0000 |
|---|---|---|
| committer | flysand7 <thebumboni@gmail.com> | 2024-12-01 11:54:56 +1100 |
| commit | 1be9833073bc34f748317f8e2beecae506a3f619 (patch) | |
| tree | fab557dba54452b2487382cd630cf780ce5117af /src | |
| parent | 9388f0d5a58fca2b263a47e6778f7e498e92ebec (diff) | |
Convert mutex guard to "try lock"
Diffstat (limited to 'src')
| -rw-r--r-- | src/types.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/types.cpp b/src/types.cpp index c51df7261..4b43662f5 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -3925,13 +3925,15 @@ gb_internal i64 *type_set_offsets_of(Slice<Entity *> const &fields, bool is_pack gb_internal bool type_set_offsets(Type *t) { t = base_type(t); if (t->kind == Type_Struct) { - MUTEX_GUARD(&t->Struct.offset_mutex); - if (!t->Struct.are_offsets_set) { - t->Struct.are_offsets_being_processed = true; - t->Struct.offsets = type_set_offsets_of(t->Struct.fields, t->Struct.is_packed, t->Struct.is_raw_union, t->Struct.custom_min_field_align, t->Struct.custom_max_field_align); - t->Struct.are_offsets_being_processed = false; - t->Struct.are_offsets_set = true; - return true; + if (mutex_try_lock(&t->Struct.offset_mutex)) { + defer (mutex_unlock(&t->Struct.offset_mutex)); + if (!t->Struct.are_offsets_set) { + t->Struct.are_offsets_being_processed = true; + t->Struct.offsets = type_set_offsets_of(t->Struct.fields, t->Struct.is_packed, t->Struct.is_raw_union, t->Struct.custom_min_field_align, t->Struct.custom_max_field_align); + t->Struct.are_offsets_being_processed = false; + t->Struct.are_offsets_set = true; + return true; + } } } else if (is_type_tuple(t)) { MUTEX_GUARD(&t->Tuple.mutex); |