| ... | @@ -2982,35 +2982,29 @@ fn parseCodeModel(arg: []const u8) std.builtin.CodeModel { | ... | @@ -2982,35 +2982,29 @@ fn parseCodeModel(arg: []const u8) std.builtin.CodeModel { |
| 2982 | /// garbage collector to run concurrently to zig processes, and to allow multiple | 2982 | /// garbage collector to run concurrently to zig processes, and to allow multiple |
| 2983 | /// zig processes to run concurrently with each other, without clobbering each other. | 2983 | /// zig processes to run concurrently with each other, without clobbering each other. |
| 2984 | fn gimmeMoreOfThoseSweetSweetFileDescriptors() void { | 2984 | fn gimmeMoreOfThoseSweetSweetFileDescriptors() void { |
| 2985 | switch (std.Target.current.os.tag) { | 2985 | if (!@hasDecl(std.os, "rlimit")) return; |
| 2986 | .windows, .wasi, .uefi, .other, .freestanding => return, | | |
| 2987 | // std lib is missing getrlimit/setrlimit. | | |
| 2988 | // https://github.com/ziglang/zig/issues/6361 | | |
| 2989 | //else => {}, | | |
| 2990 | else => return, | | |
| 2991 | } | | |
| 2992 | const posix = std.os; | 2986 | const posix = std.os; |
| 2993 | var lim = posix.getrlimit(posix.RLIMIT_NOFILE, &lim) catch return; // Oh well; we tried. | 2987 | |
| | 2988 | var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried. |
| 2994 | if (lim.cur == lim.max) return; | 2989 | if (lim.cur == lim.max) return; |
| | 2990 | |
| | 2991 | // Do a binary search for the limit. |
| | 2992 | var min: posix.rlim_t = lim.cur; |
| | 2993 | var max: posix.rlim_t = 1 << 20; |
| | 2994 | // But if there's a defined upper bound, don't search, just set it. |
| | 2995 | if (lim.max != posix.RLIM_INFINITY) { |
| | 2996 | min = lim.max; |
| | 2997 | max = lim.max; |
| | 2998 | } |
| | 2999 | |
| 2995 | while (true) { | 3000 | while (true) { |
| 2996 | // Do a binary search for the limit. | 3001 | lim.cur = min + (max - min) / 2; |
| 2997 | var min: posix.rlim_t = lim.cur; | 3002 | if (posix.setrlimit(.NOFILE, lim)) |_| { |
| 2998 | var max: posix.rlim_t = 1 << 20; | 3003 | min = lim.cur; |
| 2999 | // But if there's a defined upper bound, don't search, just set it. | 3004 | } else |_| { |
| 3000 | if (lim.max != posix.RLIM_INFINITY) { | 3005 | max = lim.cur; |
| 3001 | min = lim.max; | | |
| 3002 | max = lim.max; | | |
| 3003 | } | | |
| 3004 | while (true) { | | |
| 3005 | lim.cur = min + (max - min) / 2; | | |
| 3006 | if (posix.setrlimit(posix.RLIMIT_NOFILE, lim)) |_| { | | |
| 3007 | min = lim.cur; | | |
| 3008 | } else |_| { | | |
| 3009 | max = lim.cur; | | |
| 3010 | } | | |
| 3011 | if (min + 1 < max) continue; | | |
| 3012 | return; | | |
| 3013 | } | 3006 | } |
| | 3007 | if (min + 1 >= max) break; |
| 3014 | } | 3008 | } |
| 3015 | } | 3009 | } |
| 3016 | | 3010 | |