mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-30 03:10:06 +00:00
Remove use of mutex in single threaded code
This commit is contained in:
+1
-2
@@ -182,8 +182,7 @@ gb_internal void override_entity_in_scope(Entity *original_entity, Entity *new_e
|
|||||||
original_entity->type = new_entity->type;
|
original_entity->type = new_entity->type;
|
||||||
original_entity->aliased_of = new_entity;
|
original_entity->aliased_of = new_entity;
|
||||||
|
|
||||||
Ast *empty_ident = nullptr;
|
original_entity->identifier.store(new_entity->identifier);
|
||||||
original_entity->identifier.compare_exchange_strong(empty_ident, new_entity->identifier);
|
|
||||||
|
|
||||||
if (original_entity->identifier.load() != nullptr &&
|
if (original_entity->identifier.load() != nullptr &&
|
||||||
original_entity->identifier.load()->kind == Ast_Ident) {
|
original_entity->identifier.load()->kind == Ast_Ident) {
|
||||||
|
|||||||
+14
-5
@@ -384,6 +384,8 @@ gb_internal Entity *scope_lookup_current(Scope *s, String const &name) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gb_global bool in_single_threaded_mode_scopes = false;
|
||||||
|
|
||||||
gb_internal void scope_lookup_parent(Scope *scope, String const &name, Scope **scope_, Entity **entity_) {
|
gb_internal void scope_lookup_parent(Scope *scope, String const &name, Scope **scope_, Entity **entity_) {
|
||||||
if (scope != nullptr) {
|
if (scope != nullptr) {
|
||||||
bool gone_thru_proc = false;
|
bool gone_thru_proc = false;
|
||||||
@@ -391,9 +393,9 @@ gb_internal void scope_lookup_parent(Scope *scope, String const &name, Scope **s
|
|||||||
StringHashKey key = string_hash_string(name);
|
StringHashKey key = string_hash_string(name);
|
||||||
for (Scope *s = scope; s != nullptr; s = s->parent) {
|
for (Scope *s = scope; s != nullptr; s = s->parent) {
|
||||||
Entity **found = nullptr;
|
Entity **found = nullptr;
|
||||||
rw_mutex_shared_lock(&s->mutex);
|
if (!in_single_threaded_mode_scopes) rw_mutex_shared_lock(&s->mutex);
|
||||||
found = string_map_get(&s->elements, key);
|
found = string_map_get(&s->elements, key);
|
||||||
rw_mutex_shared_unlock(&s->mutex);
|
if (!in_single_threaded_mode_scopes) rw_mutex_shared_unlock(&s->mutex);
|
||||||
if (found) {
|
if (found) {
|
||||||
Entity *e = *found;
|
Entity *e = *found;
|
||||||
if (gone_thru_proc) {
|
if (gone_thru_proc) {
|
||||||
@@ -513,7 +515,11 @@ end:;
|
|||||||
|
|
||||||
gb_internal Entity *scope_insert(Scope *s, Entity *entity) {
|
gb_internal Entity *scope_insert(Scope *s, Entity *entity) {
|
||||||
String name = entity->token.string;
|
String name = entity->token.string;
|
||||||
return scope_insert_with_name(s, name, entity);
|
if (in_single_threaded_mode_scopes) {
|
||||||
|
return scope_insert_with_name_no_mutex(s, name, entity);
|
||||||
|
} else {
|
||||||
|
return scope_insert_with_name(s, name, entity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gb_internal Entity *scope_insert_no_mutex(Scope *s, Entity *entity) {
|
gb_internal Entity *scope_insert_no_mutex(Scope *s, Entity *entity) {
|
||||||
@@ -1795,8 +1801,7 @@ gb_internal void add_entity_use(CheckerContext *c, Ast *identifier, Entity *enti
|
|||||||
if (identifier == nullptr || identifier->kind != Ast_Ident) {
|
if (identifier == nullptr || identifier->kind != Ast_Ident) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Ast *empty_ident = nullptr;
|
entity->identifier.store(identifier);
|
||||||
entity->identifier.compare_exchange_strong(empty_ident, identifier);
|
|
||||||
|
|
||||||
identifier->Ident.entity = entity;
|
identifier->Ident.entity = entity;
|
||||||
|
|
||||||
@@ -4591,6 +4596,8 @@ gb_internal void check_single_global_entity(Checker *c, Entity *e, DeclInfo *d)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gb_internal void check_all_global_entities(Checker *c) {
|
gb_internal void check_all_global_entities(Checker *c) {
|
||||||
|
in_single_threaded_mode_scopes = true;
|
||||||
|
|
||||||
// NOTE(bill): This must be single threaded
|
// NOTE(bill): This must be single threaded
|
||||||
// Don't bother trying
|
// Don't bother trying
|
||||||
for_array(i, c->info.entities) {
|
for_array(i, c->info.entities) {
|
||||||
@@ -4610,6 +4617,8 @@ gb_internal void check_all_global_entities(Checker *c) {
|
|||||||
(void)type_align_of(e->type);
|
(void)type_align_of(e->type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
in_single_threaded_mode_scopes = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user