Commit Graph

18 Commits

Author SHA1 Message Date
Philippe Hausler
694aebb1fb Add an additional case for clocks to sleep with a wallclock deadline (#79139)
This only modifies the runtime function `swift_task_enqueueGlobalWithDeadline` to take new clock primitive to
interoperate with existing dispatch wall clock values.
2025-06-09 09:01:27 -07:00
Alastair Houghton
47fa71787f Revert "Merge pull request #80224 from glessard/revert-79789-custom-executors"
This reverts commit 06f6358067, reversing
changes made to 033f6679e8.
2025-03-28 10:15:07 +00:00
Alastair Houghton
8b15b05c63 Revert "[Concurrency] Provide a Swift interface for custom main and global executors." 2025-03-22 02:38:11 -07:00
Alastair Houghton
ed08858998 [Concurrency] Fix availability.
Fix up availability after the non-Darwin changes.  Also update the
ABI baseline.

Fix a Win32 typo.

rdar://141348916
2025-03-17 16:24:06 +00:00
Alastair Houghton
f0defd83bd [Concurrency] Add CooperativeExecutor, use it.
Also tweak the sleep implementations to let the hooks run if there
isn't a `SchedulableExecutor` (for hooked mode).

rdar://141348916
2025-03-17 13:10:35 +00:00
Alastair Houghton
8e91ae48e6 [Concurrency][Windows] Remove use of GetProcAddress().
Since we're linking `mincore.lib`, we don't need to use
`GetProcAddress()` to find `Query[Unbiased]InterruptTimePrecise()`.

rdar://135413803
2024-09-06 17:16:27 +01:00
Alastair Houghton
86c643ddc8 [Concurrency][Windows] Also update swift_get_clock_res().
I should have updated this to match as well.

rdar://135413803
2024-09-06 15:51:55 +01:00
Alastair Houghton
f5b146b095 [Windows][Concurrency] Use the same clock as Dispatch.
The Concurrency runtime calculates deadlines for scheduling itself
using `swift_get_time()`; unfortunately, on Windows that was using
`QueryPerformanceCounter()`, while Dispatch uses
`QueryInterruptTimePrecise()`.  The problem with that is that the two do
not necessarily correspond *at all*.  In general
`QueryPerformanceCounter()` may be using any of a number of hardware
timers depending on the machine on which we're running.

In the VM I was testing on, the two differed by 20ms, but the worst case
is that they are completely unrelated, in which case `Task.sleep()` will
wait essentially a random amount of time.

rdar://135413803
2024-09-06 15:39:22 +01:00
Saleem Abdulrasool
23888a4f08 Concurrency: use _BitInt(128) over __int128 (#63300)
Use the `_BitInt` extension from C2a to enable building the Concurrency library on Windows i686.

Thanks to @grynspan for the idea!
2023-01-30 18:48:23 -08:00
Jonathan Grynspan
c8ef200b5b SuspendingClock on Windows does not suspend (#63225) 2023-01-27 18:44:15 -08:00
Matt Jacobson
da855ce116 Concurrency: implement clock functions for FreeBSD
Match OpenBSD in both swift_get_time and swift_get_clock_res.
2022-12-07 02:34:59 -05:00
Yuta Saito
50e599792e [stdlib] Port SE-0329 Clock APIs to WASI
WASI doesn't have "suspending-time" concept, so use `CLOCK_MONOTONIC`
for both "continuous" and "suspending" clocks. WASI's "monotonic"
doesn't guarantee any underlying system call implementation, but most
of major implementations use `CLOCK_MONOTONIC` for all underlying
platforms.

This partially buildfixes this platform.

See also: https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#variant-cases
2022-04-29 00:50:39 +00:00
Philippe Hausler
c891f34b22 Ensure clocks properly respect leeways and use raw time for calculations for continuous clocks (#58396)
* Ensure clocks properly respect leeways and use raw time for calculations for continuous clocks

* slurp up time calcualtions to inline forms

* ensure the tolerance codepaths get tested as well

* Use task local storage for task sources in leeway based calculations

* use comparison assertions for leeway based calculations

* Whitespace cleanup

* Use the CLOCK_MONOTONIC value for linux to be compatible with linux scheduling for dispatch

* remove incorrect paren in macro check for OpenBSD

* Address feedback and remove stray ;
2022-04-27 15:41:11 -07:00
3405691582
301a406bf9 [stdlib] Buildfix OpenBSD by adding clock types. (#41857)
Reading SE-0329 and this module, two clock types are broadly defined,
"continuous", which advances during suspension, and "suspending", which
does not.

SE-0329 notes the behavior of the clock types on "Darwin and BSD" is
that `CLOCK_MONOTONIC` is "continuous" and `CLOCK_UPTIME` is
"suspending". This is also true for OpenBSD (see
https://man.openbsd.org/clock_gettime).

Update code to match. This buildfixes this platform.
2022-03-30 10:00:10 -07:00
Allan Shortlidge
1be8913c9b NFC: Fix a number of warnings emitted when building swift-frontend. 2022-03-04 16:15:33 -08:00
Karoy Lorentey
3680ea6c87 [stdlib] swift_get_clock_res: call clock_getres on Darwin, not gettime 2022-02-22 11:00:11 -08:00
Karoy Lorentey
e0a411ab52 [stdlib] Standard clocks: Fix .now and .minimumResolution implementations
These used to set the clock id incorrectly, leading to zero results. Fix that and also make the underlying entry point abort if it gets an invalid ID, preventing this from reoccurring.
2022-02-19 18:43:32 -08:00
Philippe Hausler
e675b310f8 [SE-0329] Clock/Instant/Duration (#40609)
* [WIP] Initial draft at v2 Clock/Instant/Duration

* Ensure the literal types for _DoubleWide are able to be at least 64 bits on 32 bit platforms

* static cast timespec members to long

* Remove runtime exports from clock functions

* Export clock functions in implementations as they are in headers

* Clean up internal properties by adding leading underscores, refine availability to a TBD marker macro, and break at 80 lines to match style

* Shift operators to concrete Instant types to avoid complexity in solver resolution

* Adjust diagnostic note and error expectation of ambiguities to reflect new potential solver (perhaps incorrect) solutions

* Update stdlib/public/Concurrency/TaskSleep.swift

Co-authored-by: Karoy Lorentey <klorentey@apple.com>

* [stdlib][NFC] Remove trailing whitespace

* [stdlib] Remove _DoubleWidth from stdlib's ABI

* [stdlib] Strip downd _DoubleWidth to _[U]Int128

* Additional adjustments to diagnostic notes and errors expectation of ambiguities to reflect new potential solver (perhaps incorrect) solutions

* Disable type checker performance validation for operator overload inferences (rdar://33958047)

* Decorate Duration, DurationProtocol, Instant and clocks with @available(SwiftStdlib 9999, *)

* Restore diagnostic ambiguity test assertion (due to availability)

* Add a rough attempt at implementing time accessors on win32

* Remove unused clock id, rename SPI for swift clock ids and correct a few more missing availabilities

* remove obsolete case of realtime clock for dispatch after callout

* Use the default implementation of ~ for Int128 and UInt128

* Ensure diagnostic ambiguitiy applies evenly to all platforms and their resolved types

* Restore the simd vector build modifications (merge damage)

* Update to latest naming results for Instant.Duration

* Updates to latest proposal initializers and accessors and adjust encoding/decoding to string based serialization

* Update availability for Clock/Instant/Duration methods and types to be 5.7

* Correct *Clock.now to report via the correct runtime API

* Ensure the hashing of Duration is based upon the attoseconds hashing

* Avoid string based encoding and resort back to high and low bit encoding/decoding but as unkeyed

* Adjust naming of component initializer to use suffixes on parameters

* Duration decoding should use a mutable container for decoding

* fix up components initializer and decode access

* Add platform base initializers for timespec and tiemval to and from Duration

* Add some first draft documentation for standard library types Duration, DurationProtocol and InstantProtocol

* Another round of documentation prose and some drive-by availability fixes

* InstantProtocol availability should be 5.7

* Correct linux timeval creation to be Int and not Int32

Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2022-02-17 09:32:46 -08:00