InternPool: implement thread-safe hash map

This commit is contained in:
Jacob Young 2024-06-15 16:18:41 -04:00
parent ca02266157
commit cda716ecc4
4 changed files with 450 additions and 193 deletions

View File

@ -291,3 +291,7 @@ pub fn waitAndWork(pool: *Pool, wait_group: *WaitGroup) void {
return;
}
}
pub fn getIdCount(pool: *Pool) usize {
return 1 + pool.threads.len;
}

View File

@ -1397,7 +1397,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
.error_limit = error_limit,
.llvm_object = null,
};
try zcu.init();
try zcu.init(options.thread_pool.getIdCount());
break :blk zcu;
} else blk: {
if (options.emit_h != null) return error.NoZigModuleForCHeader;
@ -2156,7 +2156,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
if (build_options.enable_debug_extensions and comp.verbose_generic_instances) {
std.debug.print("generic instances for '{s}:0x{x}':\n", .{
comp.root_name,
@as(usize, @intFromPtr(zcu)),
@intFromPtr(zcu),
});
zcu.intern_pool.dumpGenericInstances(gpa);
}

File diff suppressed because it is too large Load Diff

View File

@ -2394,9 +2394,9 @@ pub const CompileError = error{
ComptimeBreak,
};
pub fn init(mod: *Module) !void {
pub fn init(mod: *Module, thread_count: usize) !void {
const gpa = mod.gpa;
try mod.intern_pool.init(gpa);
try mod.intern_pool.init(gpa, thread_count);
try mod.global_error_set.put(gpa, .empty, {});
}