Commit graph

137 commits

Author SHA1 Message Date
Andrew Kelley
7aa4062f5c introduce Io.select and implement it in thread pool 2025-10-29 06:20:48 -07:00
Jacob Young
c4fcf85c43 Io.Condition: implement full API 2025-10-29 06:20:48 -07:00
Andrew Kelley
929b616e0f std.Io.Condition: change primitive to support only one
and no timer
2025-10-29 06:20:48 -07:00
Jacob Young
f84aca36c3 Io: implement faster mutex 2025-10-29 06:20:48 -07:00
Andrew Kelley
a1c1d06b19 std.Io: add detached async 2025-10-29 06:20:48 -07:00
Andrew Kelley
0d4b358dd8 implement Mutex, Condition, and Queue 2025-10-29 06:20:48 -07:00
Jacob Young
08b609a79f Io: implement sleep and fix cancel bugs 2025-10-29 06:20:48 -07:00
Jacob Young
5041c9ad9c EventLoop: implement thread-local queues and cancellation 2025-10-29 06:20:48 -07:00
Andrew Kelley
e7caf3a54c std.Io: introduce cancellation 2025-10-29 06:20:47 -07:00
Andrew Kelley
66b0f7e92b start adding fs functions to std.Io 2025-10-29 06:20:47 -07:00
Andrew Kelley
08bb7c6c88 free freeing wrong amount in thread pool impl 2025-10-29 06:20:47 -07:00
Andrew Kelley
31ed2d6715 fix context passing in threaded Io impl 2025-10-29 06:20:47 -07:00
Andrew Kelley
cb9f9bf58d make thread pool satisfy async/await interface 2025-10-29 06:20:47 -07:00
Andrew Kelley
21b7316772 introduce std.Io interface
which is planned to have all I/O operations in the interface, but for
now has only async and await.
2025-10-29 06:20:47 -07:00
mlugg
b866c14328
std: make RwLock test less intensive
This test called `yield` 80,000 times, which is nothing on a system with
little load, but murder on a CI system. macOS' scheduler in particular
doesn't seem to deal with this very well. The `yield` calls also weren't
even necessarily doing what they were meant to: if the optimizer could
figure out that it doesn't clobber some memory, then it could happily
reorder around the `yield`s anyway!

The test has been simplified and made to work better, and the number of
yields have been reduced. The number of overall iterations has also been
reduced, because with the `yield` calls making races very likely, we
don't really need to run too many iterations to be confident that the
implementation is race-free.
2025-10-18 09:28:43 +01:00
mlugg
7a5d2a196f
tweak tests to avoid timeouts 2025-10-18 09:28:42 +01:00
Linus Groh
eb37552536 Remove numerous things deprecated during the 0.14 release cycle
Basically everything that has a direct replacement or no uses left.

Notable omissions:

- std.ArrayHashMap: Too much fallout, needs a separate cleanup.
- std.debug.runtime_safety: Too much fallout.
- std.heap.GeneralPurposeAllocator: Lots of references to it remain, not
  a simple find and replace as "debug allocator" is not equivalent to
  "general purpose allocator".
- std.io.Reader: Is being reworked at the moment.
- std.unicode.utf8Decode(): No replacement, needs a new API first.
- Manifest backwards compat options: Removal would break test data used
  by TestFetchBuilder.
- panic handler needs to be a namespace: Many tests still rely on it
  being a function, needs a separate cleanup.
2025-07-11 08:17:43 +02:00
Pat Tullmann
cfe5defd02 linux: futex v1 API cleanup
* Use `packed struct` for flags arguments.  So, instead of
  `linux.FUTEX.WAIT` use `.{ .cmd = .WAIT, .private = true }`

* rename `futex_wait` and `futex_wake` which didn't actually specify
  wait/wake, as `futex_3arg` and `futex_4arg` (as its the number
  of parameters that is different, the `op` is whatever is specified.

* expose the full six-arg flavor of the syscall (for some of the advanced
  ops), and add packed structs for their arguments.

* Use a `packed union` to support the 4th parameter which is sometimes a
  `timespec` pointer, and sometimes a `u32`.

* Add tests that make sure the structure layout is correct and that the
  basic argument passing is working (no actual futexes are contended).
2025-06-17 22:06:39 -07:00
Alex Rønne Petersen
9d534790eb std.Target: Introduce Cpu convenience functions for feature tests.
Before:

* std.Target.arm.featureSetHas(target.cpu.features, .has_v7)
* std.Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov })
* std.Target.wasm.featureSetHasAll(target.cpu.features, .{ .atomics, .bulk_memory })

After:

* target.cpu.has(.arm, .has_v7)
* target.cpu.hasAny(.x86, &.{ .sse, .avx, .cmov })
* target.cpu.hasAll(.wasm, &.{ .atomics, .bulk_memory })
2025-06-05 06:12:00 +02:00
Andrew Kelley
1639fcea43 de-genericify SinglyLinkedList
by making it always intrusive, we make it a more broadly useful API, and
avoid binary bloat.
2025-04-03 14:55:04 -07:00
Alex Rønne Petersen
481b7bf3f0
std.Target: Remove functions that just wrap component functions.
Functions like isMinGW() and isGnuLibC() have a good reason to exist: They look
at multiple components of the target. But functions like isWasm(), isDarwin(),
isGnu(), etc only exist to save 4-8 characters. I don't think this is a good
enough reason to keep them, especially given that:

* It's not immediately obvious to a reader whether target.isDarwin() means the
  same thing as target.os.tag.isDarwin() precisely because isMinGW() and similar
  functions *do* look at multiple components.
* It's not clear where we would draw the line. The logical conclusion before
  this commit would be to also wrap Arch.isX86(), Os.Tag.isSolarish(),
  Abi.isOpenHarmony(), etc... this obviously quickly gets out of hand.
* It's nice to just have a single correct way of doing something.
2025-02-17 19:18:19 +01:00
Chris Boesch
58c00a829e
std.posix: Use separate clock ID enums for clock_gettime() and timerfd_create() (#22627) 2025-02-01 06:53:57 +00:00
Jacob Young
8c8dfb35f3 x86_64: fix crashes compiling the compiler and tests 2025-01-16 20:47:30 -05:00
Jacob Young
e5d5a8bc4e x86_64: implement switch jump tables 2025-01-16 20:42:08 -05:00
Alex Rønne Petersen
6cf01a679f std.Thread.Futex: Mark inline asm volatile in WasmImpl.
Closes #22082.
2024-11-27 23:24:37 +01:00
Andrew Kelley
862266514a Revert "Enable thread_pool function to throw errors (#20260)"
This reverts commit d346d074eb.

I would like a chance to review this, please.
2024-11-11 14:07:07 -08:00
ippsav
d346d074eb
Enable thread_pool function to throw errors (#20260)
* std.ThreadPool: allow error union return type

* allow noreturn in Pool.zig
2024-11-11 15:34:24 -06:00
Andrew Kelley
ba71079837 combine codegen work queue and linker task queue
these tasks have some shared data dependencies so they cannot be done
simultaneously. Future work should untangle these data dependencies so
that more can be done in parallel.

for now this commit ensures correctness by making linker input parsing
and codegen tasks part of the same queue.
2024-10-23 16:27:39 -07:00
David Rubin
043b1adb8d
remove @fence (#21585)
closes #11650
2024-10-04 22:21:27 +00:00
David Rubin
421fbd939c
thread: don't leak the thread in spawnManager (#21379) 2024-09-11 01:04:59 +00:00
mlugg
6808ce27bd
compiler,lib,test,langref: migrate @setCold to @branchHint 2024-08-27 00:44:35 +01:00
Andrew Kelley
e8c4e79499 std.c reorganization
It is now composed of these main sections:
* Declarations that are shared among all operating systems.
* Declarations that have the same name, but different type signatures
  depending on the operating system. Often multiple operating systems
  share the same type signatures however.
* Declarations that are specific to a single operating system.
  - These are imported one per line so you can see where they come from,
    protected by a comptime block to prevent accessing the wrong one.

Closes #19352 by changing the convention to making types `void` and
functions `{}`, so that it becomes possible to update `@hasDecl` sites
to use `@TypeOf(f) != void` or `T != void`. Happily, this ended up
removing some duplicate logic and update some bitrotted feature
detection checks.

A handful of types have been modified to gain namespacing and type
safety. This is a breaking change.

Oh, and the last usage of `usingnamespace` site is eliminated.
2024-07-19 00:30:32 -07:00
Lucas Santos
89942ebd03
Better implementation of GetLastError. (#20623)
Instead of calling the dynamically loaded kernel32.GetLastError, we can extract it from the TEB.
As shown by [Wine](34b1606019/include/winternl.h (L439)), the last error lives at offset 0x34 of the TEB in 32-bit Windows and at offset 0x68 in 64-bit Windows.
2024-07-15 10:49:51 -07:00
mochalins
c8e0095362 test: Add spawn behavior test 2024-07-09 21:15:29 -04:00
mochalins
6446596ba1 fix: Update spawn's' runFn signature 2024-07-09 21:15:29 -04:00
Jacob Young
65ced4a334 Compilation: put supported codegen backends on a separate thread
(There are no supported backends.)
2024-07-08 11:00:38 -04:00
Jacob Young
bdae01ab04 InternPool: implement and use thread-safe list for extra and limbs 2024-07-07 22:59:52 -04:00
Jacob Young
383cffbfae InternPool: temporarily disable multi-threaded behavior
This reduces the cost of the new data structure until the multi-threaded
behavior is actually used.
2024-07-07 22:59:52 -04:00
Jacob Young
cda716ecc4 InternPool: implement thread-safe hash map 2024-07-07 22:59:52 -04:00
Jacob Young
525f341f33 Zcu: introduce PerThread and pass to all the functions 2024-07-07 22:59:52 -04:00
Andrew Kelley
5fc1f8a32b std.Thread.Mutex.Recursive: alternate implementation
This version is simpler. Thanks King!
2024-06-12 18:07:39 -07:00
Andrew Kelley
506b3f6db6 introduce std.Thread.Mutex.Recursive 2024-06-12 17:43:49 -07:00
Andrew Kelley
a72292513e add std.Thread.Pool.spawnWg
This function accepts a WaitGroup parameter and manages the reference
counting therein. It also is infallible.

The existing `spawn` function is still handy when the job wants to
further schedule more tasks.
2024-05-03 20:58:02 -07:00
IntegratedQuantum
1a6485d111
Clarify the blocking behavior of RwLock.lockShared(). (#19752) 2024-04-24 10:41:13 -05:00
GethDW
db96ad4a16 std: fix Thread.Pool.spawn
`@alignCast` was required for args with greater alignment than that of a pointer.
2024-04-19 13:49:06 -07:00
Jacob Young
eb723a4070 Update uses of @fieldParentPtr to use RLS 2024-03-30 20:50:48 -04:00
Jacob Young
e409afb79b Update uses of @fieldParentPtr to pass a pointer type 2024-03-30 20:50:48 -04:00
Michael Dusan
e4ed63f138 bsd: followup to std.posix extraction from std.os
netbsd fix:
- `Futex.zig:542:56: error: expected error union type, found 'c_int'`

openbsd fix:
- `emutls.zig:10:21: error: root struct of file 'os' has no member named 'abort'`
- `Thread.zig:627:22: error: expected 6 argument(s), found 5`
2024-03-20 14:06:35 -07:00
Andrew Kelley
cd62005f19 extract std.posix from std.os
closes #5019
2024-03-19 11:45:09 -07:00
Michael Dusan
5ce40e61c6
bsd: debitrot AtomicOrder renames
- complete std.builtin.AtomicOrder renames that were missed from 6067d39522
2024-03-15 02:28:50 -04:00