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> 2022-12-10 14:34:30-05:00
logac0488430fd4ab35cab972d6409a0e244ad9637c
tree6eaa4a0f9cccb57fdc5b4fef560ca0f9fe17d97e
parenta6a141bbe9ddfbb1e46f45880244ebf1e2b2b5bb

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
...@@ -3540,7 +3540,6 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {...@@ -3540,7 +3540,6 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
3540 const cimport_zig_basename = "cimport.zig";3540 const cimport_zig_basename = "cimport.zig";
35413541
3542 var man = comp.obtainCObjectCacheManifest();3542 var man = comp.obtainCObjectCacheManifest();
3543 man.want_shared_lock = false;
3544 defer man.deinit();3543 defer man.deinit();
35453544
3546 man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects3545 man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects
...@@ -3654,7 +3653,6 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {...@@ -3654,7 +3653,6 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
3654 // possible we had a hit and the manifest is dirty, for example if the file mtime changed but3653 // possible we had a hit and the manifest is dirty, for example if the file mtime changed but
3655 // the contents were the same, we hit the cache but the manifest is dirty and we need to update3654 // the contents were the same, we hit the cache but the manifest is dirty and we need to update
3656 // it to prevent doing a full file content comparison the next time around.3655 // it to prevent doing a full file content comparison the next time around.
3657 man.want_shared_lock = true;
3658 man.writeManifest() catch |err| {3656 man.writeManifest() catch |err| {
3659 log.warn("failed to write cache manifest for C import: {s}", .{@errorName(err)});3657 log.warn("failed to write cache manifest for C import: {s}", .{@errorName(err)});
3660 };3658 };
...@@ -3829,7 +3827,6 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P...@@ -3829,7 +3827,6 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
3829 }3827 }
38303828
3831 var man = comp.obtainCObjectCacheManifest();3829 var man = comp.obtainCObjectCacheManifest();
3832 man.want_shared_lock = false;
3833 defer man.deinit();3830 defer man.deinit();
38343831
3835 man.hash.add(comp.clang_preprocessor_mode);3832 man.hash.add(comp.clang_preprocessor_mode);
...@@ -4125,7 +4122,6 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P...@@ -4125,7 +4122,6 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
4125 // possible we had a hit and the manifest is dirty, for example if the file mtime changed but4122 // possible we had a hit and the manifest is dirty, for example if the file mtime changed but
4126 // the contents were the same, we hit the cache but the manifest is dirty and we need to update4123 // the contents were the same, we hit the cache but the manifest is dirty and we need to update
4127 // it to prevent doing a full file content comparison the next time around.4124 // it to prevent doing a full file content comparison the next time around.
4128 man.want_shared_lock = true;
4129 man.writeManifest() catch |err| {4125 man.writeManifest() catch |err| {
4130 log.warn("failed to write cache manifest when compiling '{s}': {s}", .{ c_object.src.src_path, @errorName(err) });4126 log.warn("failed to write cache manifest when compiling '{s}': {s}", .{ c_object.src.src_path, @errorName(err) });
4131 };4127 };