aboutsummaryrefslogtreecommitdiff
path: root/src/Cache.zig
diff options
context:
space:
mode:
authorCody Tapscott <topolarity@tapscott.me>2022-03-01 10:42:07 -0700
committerCody Tapscott <topolarity@tapscott.me>2022-04-18 10:20:15 -0700
commit089651716c3d326f8540f4e415fc88443e42f5f2 (patch)
treebea36fa35779c13c4b50cff192a3df44258e5f04 /src/Cache.zig
parent922d8378e724063063e709223e90e3a577e4566a (diff)
downloadzig-089651716c3d326f8540f4e415fc88443e42f5f2.tar.gz
zig-089651716c3d326f8540f4e415fc88443e42f5f2.zip
stage2: Bypass file locks in src/Cache.zig for WASI targets
Diffstat (limited to 'src/Cache.zig')
-rw-r--r--src/Cache.zig18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/Cache.zig b/src/Cache.zig
index 993114905e..37cd7a7529 100644
--- a/src/Cache.zig
+++ b/src/Cache.zig
@@ -762,18 +762,22 @@ pub const Manifest = struct {
fn downgradeToSharedLock(self: *Manifest) !void {
if (!self.have_exclusive_lock) return;
- const manifest_file = self.manifest_file.?;
- try manifest_file.downgradeLock();
+ if (std.process.can_spawn or !builtin.single_threaded) { // Some targets (WASI) do not support flock
+ const manifest_file = self.manifest_file.?;
+ try manifest_file.downgradeLock();
+ }
self.have_exclusive_lock = false;
}
fn upgradeToExclusiveLock(self: *Manifest) !void {
if (self.have_exclusive_lock) return;
- const manifest_file = self.manifest_file.?;
- // Here we intentionally have a period where the lock is released, in case there are
- // other processes holding a shared lock.
- manifest_file.unlock();
- try manifest_file.lock(.Exclusive);
+ if (std.process.can_spawn or !builtin.single_threaded) { // Some targets (WASI) do not support flock
+ const manifest_file = self.manifest_file.?;
+ // Here we intentionally have a period where the lock is released, in case there are
+ // other processes holding a shared lock.
+ manifest_file.unlock();
+ try manifest_file.lock(.Exclusive);
+ }
self.have_exclusive_lock = true;
}