mirror of
https://github.com/odin-lang/Odin.git
synced 2026-06-04 01:34:39 +00:00
Make all id suffixes use atomics where possible
This commit is contained in:
@@ -157,10 +157,10 @@ gb_internal lbValue lb_equal_proc_for_type(lbModule *m, Type *type) {
|
||||
return {compare_proc->value, compare_proc->type};
|
||||
}
|
||||
|
||||
static u32 proc_index = 0;
|
||||
static std::atomic<u32> proc_index;
|
||||
|
||||
char buf[32] = {};
|
||||
isize n = gb_snprintf(buf, 32, "__$equal%u", ++proc_index);
|
||||
isize n = gb_snprintf(buf, 32, "__$equal%u", 1+proc_index.fetch_add(1));
|
||||
char *str = gb_alloc_str_len(permanent_allocator(), buf, n-1);
|
||||
String proc_name = make_string_c(str);
|
||||
|
||||
@@ -656,10 +656,10 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) {
|
||||
GB_ASSERT(*found != nullptr);
|
||||
return {(*found)->value, (*found)->type};
|
||||
}
|
||||
static u32 proc_index = 0;
|
||||
static std::atomic<u32> proc_index;
|
||||
|
||||
char buf[32] = {};
|
||||
isize n = gb_snprintf(buf, 32, "__$map_set-%u", ++proc_index);
|
||||
isize n = gb_snprintf(buf, 32, "__$map_set-%u", 1+proc_index.fetch_add(1));
|
||||
char *str = gb_alloc_str_len(permanent_allocator(), buf, n-1);
|
||||
String proc_name = make_string_c(str);
|
||||
|
||||
@@ -774,7 +774,8 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) {
|
||||
|
||||
|
||||
gb_internal lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, Ast *expr, lbProcedure *parent) {
|
||||
MUTEX_GUARD(&m->gen->anonymous_proc_lits_mutex);
|
||||
mutex_lock(&m->gen->anonymous_proc_lits_mutex);
|
||||
defer (mutex_unlock(&m->gen->anonymous_proc_lits_mutex));
|
||||
|
||||
lbProcedure **found = map_get(&m->gen->anonymous_proc_lits, expr);
|
||||
if (found) {
|
||||
@@ -788,7 +789,7 @@ gb_internal lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &pr
|
||||
isize name_len = prefix_name.len + 6 + 11;
|
||||
char *name_text = gb_alloc_array(permanent_allocator(), char, name_len);
|
||||
static std::atomic<i32> name_id;
|
||||
name_len = gb_snprintf(name_text, name_len, "%.*s$anon-%d", LIT(prefix_name), name_id.fetch_add(1));
|
||||
name_len = gb_snprintf(name_text, name_len, "%.*s$anon-%d", LIT(prefix_name), 1+name_id.fetch_add(1));
|
||||
String name = make_string((u8 *)name_text, name_len-1);
|
||||
|
||||
Type *type = type_of_expr(expr);
|
||||
|
||||
@@ -164,7 +164,7 @@ struct lbModule {
|
||||
PtrMap<Type *, lbProcedure *> map_get_procs;
|
||||
PtrMap<Type *, lbProcedure *> map_set_procs;
|
||||
|
||||
u32 nested_type_name_guid;
|
||||
std::atomic<u32> nested_type_name_guid;
|
||||
|
||||
Array<lbProcedure *> procedures_to_generate;
|
||||
Array<Entity *> global_procedures_and_types_to_create;
|
||||
|
||||
@@ -1426,7 +1426,7 @@ gb_internal String lb_set_nested_type_name_ir_mangled_name(Entity *e, lbProcedur
|
||||
if (p != nullptr) {
|
||||
isize name_len = p->name.len + 1 + ts_name.len + 1 + 10 + 1;
|
||||
char *name_text = gb_alloc_array(permanent_allocator(), char, name_len);
|
||||
u32 guid = ++p->module->nested_type_name_guid;
|
||||
u32 guid = 1+p->module->nested_type_name_guid.fetch_add(1);
|
||||
name_len = gb_snprintf(name_text, name_len, "%.*s.%.*s-%u", LIT(p->name), LIT(ts_name), guid);
|
||||
|
||||
String name = make_string(cast(u8 *)name_text, name_len-1);
|
||||
@@ -1436,9 +1436,8 @@ gb_internal String lb_set_nested_type_name_ir_mangled_name(Entity *e, lbProcedur
|
||||
// NOTE(bill): a nested type be required before its parameter procedure exists. Just give it a temp name for now
|
||||
isize name_len = 9 + 1 + ts_name.len + 1 + 10 + 1;
|
||||
char *name_text = gb_alloc_array(permanent_allocator(), char, name_len);
|
||||
static u32 guid = 0;
|
||||
guid += 1;
|
||||
name_len = gb_snprintf(name_text, name_len, "_internal.%.*s-%u", LIT(ts_name), guid);
|
||||
static std::atomic<u32> guid;
|
||||
name_len = gb_snprintf(name_text, name_len, "_internal.%.*s-%u", LIT(ts_name), 1+guid.fetch_add(1));
|
||||
|
||||
String name = make_string(cast(u8 *)name_text, name_len-1);
|
||||
e->TypeName.ir_mangled_name = name;
|
||||
|
||||
Reference in New Issue
Block a user