diff options
| author | Casey Banner <kcbanner@gmail.com> | 2023-01-04 14:51:43 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-04 14:51:43 -0500 |
| commit | a3e2ee091139740d076da1176ac8c487ca20a9a6 (patch) | |
| tree | 9b8c8aaaa8166a7b0f338b0b07755e936c66ec1e /src/Compilation.zig | |
| parent | 9ed4a93ae7244a02071196e8913f43bcc9144c25 (diff) | |
| download | zig-a3e2ee091139740d076da1176ac8c487ca20a9a6.tar.gz zig-a3e2ee091139740d076da1176ac8c487ca20a9a6.zip | |
Fix another LockViolation case on Windows (#14162)
- Add an assert that an exclusive lock is help to writeManifest
- Only call writeManifest in updateCObject if an exclusive lock is held
- cache: fixup test to verify hits don't take an exclusive lock, instead of writing the manifest
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 8249a8e9db..e365d1dab2 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -3681,13 +3681,15 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult { break :digest digest; } else man.final(); - // Write the updated manifest. This is a no-op if the manifest is not dirty. Note that it is - // 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.writeManifest() catch |err| { - log.warn("failed to write cache manifest for C import: {s}", .{@errorName(err)}); - }; + if (man.have_exclusive_lock) { + // Write the updated manifest. This is a no-op if the manifest is not dirty. Note that it is + // 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.writeManifest() catch |err| { + log.warn("failed to write cache manifest for C import: {s}", .{@errorName(err)}); + }; + } const out_zig_path = try comp.local_cache_directory.join(comp.gpa, &[_][]const u8{ "o", &digest, cimport_zig_basename, @@ -4086,13 +4088,15 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P break :blk digest; }; - // Write the updated manifest. This is a no-op if the manifest is not dirty. Note that it is - // 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.writeManifest() catch |err| { - log.warn("failed to write cache manifest when compiling '{s}': {s}", .{ c_object.src.src_path, @errorName(err) }); - }; + if (man.have_exclusive_lock) { + // Write the updated manifest. This is a no-op if the manifest is not dirty. Note that it is + // 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.writeManifest() catch |err| { + log.warn("failed to write cache manifest when compiling '{s}': {s}", .{ c_object.src.src_path, @errorName(err) }); + }; + } const o_basename = try std.fmt.allocPrint(arena, "{s}{s}", .{ o_basename_noext, o_ext }); |
