Commit graph

122 commits

Author SHA1 Message Date
Andrew Kelley
13b537d77c std.Io.Threaded: remove dead code 2025-11-21 19:54:41 -08:00
Andrew Kelley
aae85a4130 std.Io.Threaded: allow calling init in single-threaded mode 2025-11-21 19:54:41 -08:00
Loris Cro
69f9395b38 fix logic bug in groupAsync 2025-11-21 19:54:41 -08:00
Loris Cro
ff883dd6ce fix single-threaded builds 2025-11-21 19:54:41 -08:00
Loris Cro
8eaebf5939 Io.Threaded PoC reimplementation
This is a reimplementation of Io.Threaded that fixes the issues
highlighted in the recent Zulip discussion. It's poorly tested but it
does successfully run to completion the litmust test example that I
offered in the discussion.

This implementation has the following key design decisions:

- `t.cpu_count` is used as the threadpool size.
- `t.concurrency_limit` is used as the maximum number of
  "burst, one-shot" threads that can be spawned by `io.concurrent` past
  `t.cpu_count`.
- `t.available_thread_count` is the number of threads in the pool that
  is not currently busy with work (the bookkeeping happens in the worker
  function).
- `t.one_shot_thread_count` is the number of active threads that were
  spawned by `io.concurrent` past `t.cpu_count`.

In this implementation:

- `io.async` first tries to decrement `t.available_thread_count`. If
  there are no threads available, it tries to spawn a new one if possible,
  otherwise it runs the task immediately.
- `io.concurrent` first tries to use a thread in the pool same as
  `io.async`, but on failure (no available threads and pool size limit
  reached) it tries to spawn a new one-shot thread. One shot threads
  run a different main function that just executes one task, decrements
  the number of active one shot threads, and then exits.

A relevant future improvement is to have one-shot threads stay on for a
few seconds (and potentially pick up a new task) to amortize spawning
costs.
2025-11-21 19:54:41 -08:00
rpkak
6b4f45f782 system specific errno 2025-11-20 15:03:23 -08:00
Benjamin Jurk
4b5351bc0d
update deprecated ArrayListUnmanaged usage (#25958) 2025-11-20 14:46:23 -08:00
Jan200101
bd832ed39a std.Io.Threaded: add missing statx masks
statx does not guarantee that the values requested by the mask be
present and those not requested be absent which is why this worked.
2025-11-19 20:13:25 +01:00
Alex Rønne Petersen
9ab7eec23e represent Mac Catalyst as aarch64-maccatalyst-none rather than aarch64-ios-macabi
Apple's own headers and tbd files prefer to think of Mac Catalyst as a distinct
OS target. Earlier, when DriverKit support was added to LLVM, it was represented
a distinct OS. So why Apple decided to only represent Mac Catalyst as an ABI in
the target triple is beyond me. But this isn't the first time they've ignored
established target triple norms (see: armv7k and aarch64_32) and it probably
won't be the last.

While doing this, I also audited all Darwin OS prongs throughout the codebase
and made sure they cover all the tags.
2025-11-14 11:33:35 +01:00
Carl Åstholm
cca2d09950 io: Correctly align async closure contexts
This fixes package fetching on Windows.

Previously, `Async/GroupClosure` allocations were only aligned for the
closure struct type, which resulted in panics when `context_alignment`
(or `result_alignment` for that matter) had a greater alignment.
2025-11-11 01:11:45 +01:00
Carl Åstholm
ed7f2588e4 io: Translate Windows Clock.real timestamps to the POSIX/Unix epoch
This fixes `std.http.Client` TLS certificate validation on Windows.
2025-11-10 22:12:39 +01:00
Linus Groh
afdd04356c std: serenity has preadv now
2a9154e77c
2025-11-02 14:45:32 -08:00
Alex Rønne Petersen
5db9eaa851
std.Io.Threaded: use ResetEventPosix on illumos
Like NetBSD, illumos has no futexes.

ref #25760
2025-11-01 16:18:56 +01:00
Jacob Young
1d80c9540a Threaded: fix safety crashes 2025-10-29 21:01:47 -04:00
Andrew Kelley
05b28409e7 std.Io.Threaded: install and cleanup signal handlers
rather than in start code. delete std.options.keep_sig_io and
std.options.keep_sig_pipe
2025-10-29 06:20:52 -07:00
Andrew Kelley
c40204a3e5 std.Io: add unit tests for Group and concurrent 2025-10-29 06:20:52 -07:00
Andrew Kelley
03fd132b1c std.Io: fix Group.wait unsoundness
Previously if a Group.wait was canceled, then a subsequent call to
wait() or cancel() would trip an assertion in the synchronization code.
2025-10-29 06:20:52 -07:00
Andrew Kelley
6c794ce7bc std.Io.Threaded.dirOpenFileWtf16: SHARING_VIOLATION
is the error code that needs the kernel bug workaround, not
ACCESS_DENIED.
2025-10-29 06:20:52 -07:00
Andrew Kelley
6f64c8b693 std.debug.SelfInfo.Windows: less invasive change
restores code closer to master branch in hopes of avoiding a regression
that was introduced when this was based on openSelfExe rather than
GetModuleFileNameExW.
2025-10-29 06:20:52 -07:00
Andrew Kelley
030b630829 std.Io.Threaded: fix EBADF error code on wasm32-wasi -lc when reading 2025-10-29 06:20:52 -07:00
Andrew Kelley
c4dc7d7c3d std.Io.Threaded: implement Unix sockets for Windows 2025-10-29 06:20:52 -07:00
Andrew Kelley
b39f3d294d std.Io.Threaded: implement dirMakeOpenPath for WASI
and fix error code when file operation occurs on director handle
2025-10-29 06:20:52 -07:00
Andrew Kelley
4114392369 std: fix definition of ws2_32.GetAddrInfoExW
There was a missing parameter.
2025-10-29 06:20:52 -07:00
Andrew Kelley
f5870b267e std.Io.Threaded: fix typo in panic message 2025-10-29 06:20:52 -07:00
Andrew Kelley
94b9874981 std.Io.Threaded: stub out netbsd mutex and condition 2025-10-29 06:20:52 -07:00
Andrew Kelley
a28d3059e6 std.Io.Threaded: implement ResetEvent in terms of pthreads
needed for NetBSD
2025-10-29 06:20:52 -07:00
Andrew Kelley
30448d92af std.Io.Threaded: fix netLookup for Windows
* respect address family option
* fix port number using wrong buffer
2025-10-29 06:20:52 -07:00
Andrew Kelley
135ec79f50 std.Io.File: fix stat for Windows 2025-10-29 06:20:51 -07:00
Andrew Kelley
cc4931b325 std.Io.Threaded: fix 32-bit overflow in lookupDns
be a little more careful with nanoseconds
2025-10-29 06:20:51 -07:00
Andrew Kelley
3de1b6c9a9 std.Io.Threaded: better clock lowering for BSDs 2025-10-29 06:20:51 -07:00
Andrew Kelley
8b269f7e18 std: make signal numbers into an enum
fixes start logic for checking whether IO/POLL exist
2025-10-29 06:20:51 -07:00
Andrew Kelley
cc751c01f1 std.Io.Threaded: correct clockToPosix for FreeBSD 2025-10-29 06:20:51 -07:00
Andrew Kelley
4e95c2eb1b std.Io.Threaded: implement futexes for freebsd 2025-10-29 06:20:51 -07:00
Andrew Kelley
0caf286a1a std.Io.Threaded: don't skip executing canceled group closures 2025-10-29 06:20:51 -07:00
Andrew Kelley
df4c30ca16 link: move the windows kernel bug workaround to Io implementation 2025-10-29 06:20:51 -07:00
Andrew Kelley
6ccb53bff1 std.Io.Threaded: fix openSelfExe for Windows
missing a call to wToPrefixedFileW
2025-10-29 06:20:51 -07:00
Andrew Kelley
f6c5525c84 std.Io.Threaded: fix compilation on pthreads linux 2025-10-29 06:20:51 -07:00
Andrew Kelley
fd7475c8b2 std.Io.Threaded: implement netWrite for Windows 2025-10-29 06:20:51 -07:00
Andrew Kelley
6cff32c7ee std.Io.Threaded: implement netRead for Windows 2025-10-29 06:20:51 -07:00
Andrew Kelley
a8f95e5176 std.Io.Threaded: implement cancellation for pthreads
not to be confused with pthread_cancel, which is a useless API.
2025-10-29 06:20:51 -07:00
Andrew Kelley
85e159e652 std.Io.Threaded: closures must always be run even when canceled 2025-10-29 06:20:51 -07:00
Andrew Kelley
ae86c0f529 std.Io: adjust concurrent error set
Now std.Io.Threaded can return error.ConcurrencyUnavailable rather than
asserting. This is handy for logic that wants to try a concurrent
implementation but then fall back to a synchronous one.
2025-10-29 06:20:51 -07:00
Andrew Kelley
ecdc00466c std.Io.net: make it easier to use netReceiveMany correctly 2025-10-29 06:20:51 -07:00
Andrew Kelley
46f7e3ea9f std.Io.Threaded: add ioBasic which disables networking 2025-10-29 06:20:51 -07:00
Andrew Kelley
5c527a1854 std.Io.Threaded: implement fileStat for Windows 2025-10-29 06:20:51 -07:00
Andrew Kelley
5d7672f2ad std.Io.Threaded: stub netConnectUnix for Windows 2025-10-29 06:20:51 -07:00
Andrew Kelley
a1f177d637 std.Io.Threaded: stub netListenUnix for Windows 2025-10-29 06:20:51 -07:00
Andrew Kelley
1b0dcd4007 std.Io.Threaded: fix setting of O_NONBLOCK flag 2025-10-29 06:20:51 -07:00
Andrew Kelley
df84dc18bc add bind 2025-10-29 06:20:51 -07:00
Andrew Kelley
59ffa607a4 std.Io.Threaded: fix sending invalid pointer
OS wants valid control pointer even when len is zero
2025-10-29 06:20:51 -07:00