aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorCasey Banner <kcbanner@gmail.com>2022-12-06 23:15:54 -0500
committerGitHub <noreply@github.com>2022-12-06 23:15:54 -0500
commit8ccb9a6ad327a4d7fbc321b33d4aa66a27a1f5ee (patch)
tree13556a64c4a9af587f12605085b4c880334772e3 /src/Compilation.zig
parent14416b522e697997f21dd634bfdc70fbff59471b (diff)
downloadzig-8ccb9a6ad327a4d7fbc321b33d4aa66a27a1f5ee.tar.gz
zig-8ccb9a6ad327a4d7fbc321b33d4aa66a27a1f5ee.zip
cache: Fix LockViolation during C compilation paths (#13591)
- C compilation flows didn't hold an exclusive lock on the cache manifest file when writing to it in all cases - On windows, explicitly unlock the file lock before closing it
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index e3c45678e2..f568753fea 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -3565,6 +3565,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
const cimport_zig_basename = "cimport.zig";
var man = comp.obtainCObjectCacheManifest();
+ man.want_shared_lock = false;
defer man.deinit();
man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects
@@ -3678,6 +3679,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
// possible we had a hit and the manifest is dirty, for example if the file mtime changed but
// the contents were the same, we hit the cache but the manifest is dirty and we need to update
// it to prevent doing a full file content comparison the next time around.
+ man.want_shared_lock = true;
man.writeManifest() catch |err| {
log.warn("failed to write cache manifest for C import: {s}", .{@errorName(err)});
};
@@ -3852,6 +3854,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
}
var man = comp.obtainCObjectCacheManifest();
+ man.want_shared_lock = false;
defer man.deinit();
man.hash.add(comp.clang_preprocessor_mode);
@@ -4147,6 +4150,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
// possible we had a hit and the manifest is dirty, for example if the file mtime changed but
// the contents were the same, we hit the cache but the manifest is dirty and we need to update
// it to prevent doing a full file content comparison the next time around.
+ man.want_shared_lock = true;
man.writeManifest() catch |err| {
log.warn("failed to write cache manifest when compiling '{s}': {s}", .{ c_object.src.src_path, @errorName(err) });
};