authorgravatar for topolarity@tapscott.meCody Tapscott <topolarity@tapscott.me> 2022-03-01 10:42:07-07:00
committergravatar for topolarity@tapscott.meCody Tapscott <topolarity@tapscott.me> 2022-04-18 10:20:15-07:00
log089651716c3d326f8540f4e415fc88443e42f5f2
treebea36fa35779c13c4b50cff192a3df44258e5f04
parent922d8378e724063063e709223e90e3a577e4566a

stage2: Bypass file locks in src/Cache.zig for WASI targets


1 files changed, 11 insertions(+), 7 deletions(-)

src/Cache.zig+11-7
...@@ -762,18 +762,22 @@ pub const Manifest = struct {...@@ -762,18 +762,22 @@ pub const Manifest = struct {
762762
763 fn downgradeToSharedLock(self: *Manifest) !void {763 fn downgradeToSharedLock(self: *Manifest) !void {
764 if (!self.have_exclusive_lock) return;764 if (!self.have_exclusive_lock) return;
765 const manifest_file = self.manifest_file.?;765 if (std.process.can_spawn or !builtin.single_threaded) { // Some targets (WASI) do not support flock
766 try manifest_file.downgradeLock();766 const manifest_file = self.manifest_file.?;
767 try manifest_file.downgradeLock();
768 }
767 self.have_exclusive_lock = false;769 self.have_exclusive_lock = false;
768 }770 }
769771
770 fn upgradeToExclusiveLock(self: *Manifest) !void {772 fn upgradeToExclusiveLock(self: *Manifest) !void {
771 if (self.have_exclusive_lock) return;773 if (self.have_exclusive_lock) return;
772 const manifest_file = self.manifest_file.?;774 if (std.process.can_spawn or !builtin.single_threaded) { // Some targets (WASI) do not support flock
773 // Here we intentionally have a period where the lock is released, in case there are775 const manifest_file = self.manifest_file.?;
774 // other processes holding a shared lock.776 // Here we intentionally have a period where the lock is released, in case there are
775 manifest_file.unlock();777 // other processes holding a shared lock.
776 try manifest_file.lock(.Exclusive);778 manifest_file.unlock();
779 try manifest_file.lock(.Exclusive);
780 }
777 self.have_exclusive_lock = true;781 self.have_exclusive_lock = true;
778 }782 }
779783