mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:44:43 +01:00
Compilation: fix appendFileSystemInput race between main thread and C object workers
Co-authored-by: Matthew Lugg <mlugg@mlugg.co.uk>
This commit is contained in:
parent
28c5cc390c
commit
621e1d7b1e
1 changed files with 5 additions and 4 deletions
|
|
@ -3231,6 +3231,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
|
|||
}
|
||||
}
|
||||
|
||||
/// Thread-safe. Assumes that `comp.mutex` is *not* already held by the caller.
|
||||
pub fn appendFileSystemInput(comp: *Compilation, path: Compilation.Path) Allocator.Error!void {
|
||||
const gpa = comp.gpa;
|
||||
const fsi = comp.file_system_inputs orelse return;
|
||||
|
|
@ -3251,6 +3252,10 @@ pub fn appendFileSystemInput(comp: *Compilation, path: Compilation.Path) Allocat
|
|||
.{ @tagName(path.root), want_prefix_dir, path.sub_path },
|
||||
);
|
||||
|
||||
// There may be concurrent calls to this function from C object workers and/or the main thread.
|
||||
comp.mutex.lock();
|
||||
defer comp.mutex.unlock();
|
||||
|
||||
try fsi.ensureUnusedCapacity(gpa, path.sub_path.len + 3);
|
||||
if (fsi.items.len > 0) fsi.appendAssumeCapacity(0);
|
||||
fsi.appendAssumeCapacity(prefix);
|
||||
|
|
@ -6443,10 +6448,6 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
|
|||
return error.InvalidDepFile;
|
||||
},
|
||||
};
|
||||
|
||||
// There may be concurrent calls to `appendFileSystemInput` from other C objects.
|
||||
comp.mutex.lock();
|
||||
defer comp.mutex.unlock();
|
||||
try comp.appendFileSystemInput(input_path);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue