authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-09 22:16:10-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-09 15:02:38-07:00
log07f6fc30002b479d711a3a990dab75686cf14bec
tree7d851e643a7107fc90e681a2876e2de001ffb04b
parenta4418a8fd6663f532a021c3ad2ae807a6ccd62cc

Compilation: revert asking for exclusive locks on cache hits

We definitely want a shared lock on a cache hit. Without this, we get a deadlock when Zig is asked to compile the same C source file multiple times as part of the same compilation. This is a partial revert of 8ccb9a6ad327a4d7fbc321b33d4aa66a27a1f5ee. cc @kcbanner

1 files changed, 0 insertions(+), 4 deletions(-)

src/Compilation.zig-4
......@@ -3580,7 +3580,6 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
35803580 const cimport_zig_basename = "cimport.zig";
35813581
35823582 var man = comp.obtainCObjectCacheManifest();
3583 man.want_shared_lock = false;
35843583 defer man.deinit();
35853584
35863585 const use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1;
......@@ -3698,7 +3697,6 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
36983697 // possible we had a hit and the manifest is dirty, for example if the file mtime changed but
36993698 // the contents were the same, we hit the cache but the manifest is dirty and we need to update
37003699 // it to prevent doing a full file content comparison the next time around.
3701 man.want_shared_lock = true;
37023700 man.writeManifest() catch |err| {
37033701 log.warn("failed to write cache manifest for C import: {s}", .{@errorName(err)});
37043702 };
......@@ -3873,7 +3871,6 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
38733871 }
38743872
38753873 var man = comp.obtainCObjectCacheManifest();
3876 man.want_shared_lock = false;
38773874 defer man.deinit();
38783875
38793876 man.hash.add(comp.clang_preprocessor_mode);
......@@ -4167,7 +4164,6 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
41674164 // possible we had a hit and the manifest is dirty, for example if the file mtime changed but
41684165 // the contents were the same, we hit the cache but the manifest is dirty and we need to update
41694166 // it to prevent doing a full file content comparison the next time around.
4170 man.want_shared_lock = true;
41714167 man.writeManifest() catch |err| {
41724168 log.warn("failed to write cache manifest when compiling '{s}': {s}", .{ c_object.src.src_path, @errorName(err) });
41734169 };