diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Compilation.zig | 12 | ||||
| -rw-r--r-- | src/ThreadPool.zig | 6 | ||||
| -rw-r--r-- | src/stage1/zig0.cpp | 4 |
3 files changed, 17 insertions, 5 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 1c27a589ee..23f67f5b37 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1728,7 +1728,7 @@ fn workerUpdateCObject( error.AnalysisFail => return, else => { { - var lock = comp.mutex.acquire(); + const lock = comp.mutex.acquire(); defer lock.release(); comp.failed_c_objects.ensureCapacity(comp.gpa, comp.failed_c_objects.items().len + 1) catch { fatal("TODO handle this by setting c_object.status = oom failure", .{}); @@ -1759,7 +1759,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: * if (c_object.clearStatus(comp.gpa)) { // There was previous failure. - var lock = comp.mutex.acquire(); + const lock = comp.mutex.acquire(); defer lock.release(); comp.failed_c_objects.removeAssertDiscard(c_object); } @@ -1789,10 +1789,12 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: * { const is_collision = blk: { - var lock = comp.mutex.acquire(); + const bin_digest = man.hash.peekBin(); + + const lock = comp.mutex.acquire(); defer lock.release(); - const gop = try comp.c_object_cache_digest_set.getOrPut(comp.gpa, man.hash.peekBin()); + const gop = try comp.c_object_cache_digest_set.getOrPut(comp.gpa, bin_digest); break :blk gop.found_existing; }; if (is_collision) { @@ -2211,7 +2213,7 @@ fn failCObj(comp: *Compilation, c_object: *CObject, comptime format: []const u8, fn failCObjWithOwnedErrorMsg(comp: *Compilation, c_object: *CObject, err_msg: *ErrorMsg) InnerError { { - var lock = comp.mutex.acquire(); + const lock = comp.mutex.acquire(); defer lock.release(); { errdefer err_msg.destroy(comp.gpa); diff --git a/src/ThreadPool.zig b/src/ThreadPool.zig index 7d6af3d24c..00cb26772a 100644 --- a/src/ThreadPool.zig +++ b/src/ThreadPool.zig @@ -25,6 +25,8 @@ pub fn init(self: *ThreadPool, allocator: *std.mem.Allocator) !void { .allocator = allocator, .threads = &[_]*std.Thread{}, }; + if (std.builtin.single_threaded) + return; errdefer self.deinit(); @@ -67,6 +69,10 @@ pub fn shutdown(self: *ThreadPool) void { } pub fn spawn(self: *ThreadPool, comptime func: anytype, args: anytype) !void { + if (std.builtin.single_threaded) { + @call(.{}, func, args); + return; + } const Args = @TypeOf(args); const Closure = struct { arguments: Args, diff --git a/src/stage1/zig0.cpp b/src/stage1/zig0.cpp index 73f5b4f685..bcc9dbc00a 100644 --- a/src/stage1/zig0.cpp +++ b/src/stage1/zig0.cpp @@ -266,6 +266,7 @@ int main(int argc, char **argv) { TargetSubsystem subsystem = TargetSubsystemAuto; const char *override_lib_dir = nullptr; const char *mcpu = nullptr; + bool single_threaded = false; for (int i = 1; i < argc; i += 1) { char *arg = argv[i]; @@ -281,6 +282,8 @@ int main(int argc, char **argv) { optimize_mode = BuildModeSafeRelease; } else if (strcmp(arg, "-OReleaseSmall") == 0) { optimize_mode = BuildModeSmallRelease; + } else if (strcmp(arg, "--single-threaded") == 0) { + single_threaded = true; } else if (strcmp(arg, "--help") == 0) { return print_full_usage(arg0, stdout, EXIT_SUCCESS); } else if (strcmp(arg, "--strip") == 0) { @@ -469,6 +472,7 @@ int main(int argc, char **argv) { stage1->link_libcpp = link_libcpp; stage1->subsystem = subsystem; stage1->pic = true; + stage1->is_single_threaded = single_threaded; zig_stage1_build_object(stage1); |
