Commit Graph

1608 Commits

Author SHA1 Message Date
Ben Rimmington
ce0794cc31 [SE-0329] Update the Task.sleep(for:) method (#60400) 2022-08-12 11:29:07 +01:00
Alex Martini
f8b716947d Add missing 'try' for throwing async code.
Fixes <rdar://97022479>
2022-07-21 11:25:39 -07:00
Nate Chandler
34c08b8344 [TaskToThread] Add Task.runInline.
The new intrinsic, exposed via static functions on Task<T, Never> and
Task<T, Error> (rethrowing), begins an asynchronous context within a
synchronous caller's context.  This is only available for use under the
task-to-thread concurrency model, and even then only under SPI.
2022-07-08 08:44:18 -07:00
Nate Chandler
59f6cbc385 [NFC] Extracted function for header/context size.
So that this functionality is available elsewhere, extract it from
swift_task_create_commonImpl into a reusable static functions.
2022-07-06 11:51:16 -07:00
Nate Chandler
da45a67192 [NFC] Removed unused argument.
Previously getAsyncClosureEntryPointAndContextSize took both a pointer
for a function and a closure context.  That was a relic of a temporary
ABI where async function pointers were not used in all cases.  Now that
that ABI is long gone, async function pointers are always used.
Consequently, the closure context argument was unused.  Here, the
closure context argument is removed.
2022-07-06 11:51:16 -07:00
Nate Chandler
68eea8adec [TaskToThread] No unstructured tasks.
In this mode, the following are disabled:

- task creation
- global actors
- MainActor
- custom executors
2022-07-06 11:51:16 -07:00
Stephen Celis
8be672a8ae Add Task.sleep(for: Duration) (#59203)
* Add Task.sleep(for: Duration)

* Update TaskSleepDuration.swift

* Update stdlib/public/Concurrency/TaskSleepDuration.swift

Co-authored-by: Alex Martini <amartini@apple.com>

* Update stdlib/public/Concurrency/TaskSleepDuration.swift

Co-authored-by: Alex Martini <amartini@apple.com>

* Fix suggestion.

* Update stdlib/public/Concurrency/TaskSleepDuration.swift

Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>

* Update stdlib/public/Concurrency/TaskSleepDuration.swift

Co-authored-by: Alex Martini <amartini@apple.com>
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2022-06-27 09:05:36 -07:00
Karoy Lorentey
789545d1be Merge pull request #41843 from lorentey/adopt-primary-associated-types
[SE-0358][stdlib] Adopt primary associated types
2022-06-24 10:46:29 -07:00
Konrad `ktoso` Malawski
53168355f0 [Distributed] Explicitly ban a class extending AnyActor as well 2022-06-22 09:21:55 +09:00
Saleem Abdulrasool
a35c7b38dd Concurency: add Windows.h include
The Windows path uses `LoadLibrary` which should use `Windows.h` for the
declaration as per MSDN.  This avoids an unnecessary warning when
building for Windows.
2022-06-19 09:42:21 -07:00
Mike Ash
30cb7a20c3 Merge pull request #59349 from mikeash/concurrency-tracing-log-categories
[Concurrency] Set final subsystem/categories for concurrency tracing.
2022-06-15 11:14:25 -04:00
Mike Ash
72499c5753 [Concurrency] Set final subsystem/categories for concurrency tracing. 2022-06-13 11:36:09 -04:00
John McCall
ef80a315f8 When waiting on a task, escalate it before enqueuing the waiting task.
As soon as the waiting task is successfully enqueued on the blocking
task, both tasks have to be considered invalidated because the
blocking task can concurrently complete and resume its waiters:

- The waiting task ensures that the blocking task is valid while
  it's waiting.  However, that's measured from the perspective of
  the waiting task, not from the perspective of the thread that was
  previously executing it.  As soon as the waiting task is resumed,
  the wait call completes and the validity guarantee on the blocking
  task disappears, so the blocking task must be treated as
  invalidated.

- The waiting task ensures that it is valid as long as it isn't
  complete.  Since it's trying to wait, it must not be complete.
  However, as soon we resume it, it can complete, so the waiting
  task must also be treated as invalidated.

This is one of those things that's not really easy to test, and the
need for a fix is pretty urgent, so I'm submitting this patch without
a test.  I'll try to land a race test that demonstrates the bug in
the next few days.

@kavon deserves all the credit here for some truly heroic debugging
and finally recognizing the flaw in the code; I'm just popping in
at the last minute to sheepishly patch the bug.

Fixes rdar://92666987
2022-06-10 23:39:59 -04:00
Alastair Houghton
124581a810 [Build][Concurrency] Fix Concurrency build to work for Linux.
`SWIFT_BUILD_STATIC_STDLIB` is not mutually exclusive with
`SWIFT_BUILD_DYNAMIC_STDLIB`, and Linux sets both, so we can't use
`SWIFT_BUILD_STATIC_STDLIB` to conditionalise things.

The linker error about duplicate definitions for the threading error
handler was happening because we were forced to include the object
containing that symbol; moving it to another object should fix that.

And it turns out there's a way to get CMake to include the threading
object library only when building a shared object, so use that too.

rdar://90776105
2022-06-07 07:39:53 +01:00
Alastair Houghton
33f103f03e [Build] Fix some issues with the standalone library build.
When we're building static libraries, we don't need to include the
threading objects in both Concurrency and Core, and we also don't need
two copies of the threading library's fatal error handler.

rdar://90776105
2022-06-07 07:39:53 +01:00
Alastair Houghton
48255788dd [Concurrency] Remove redundant include.
Clean up an unnecesary include.

rdar://90776105
2022-06-07 07:39:53 +01:00
Alastair Houghton
eb4c81d60e [Threading] Don't use TLS keys as template arguments.
There's no guarantee that e.g. pthread_key_t is an integral type.  It could
be some kind of struct, or some other thing that isn't valid as a template
argument.

rdar://90776105
2022-06-07 07:39:53 +01:00
Alastair Houghton
c7c1c1be80 [Threading] Fix some problems with the C11 threading code.
These changes are needed to get things building with a C11 threads shim
header on macOS.

rdar://90776105
2022-06-07 07:39:53 +01:00
Alastair Houghton
0e9318cec5 [Threading] Put everything through git clang-format.
Just formatting changes.

rdar://90776105
2022-06-07 07:39:53 +01:00
Alastair Houghton
ef2e40a937 [Concurrency][Windows] Remove unnecessary includes.
TaskLocal.cpp doesn't need <handleapi.h> or <processthreadsapi.h>, both of
which want <windows.h>, which isn't included any more.

rdar://90776105
2022-06-07 07:39:52 +01:00
Alastair Houghton
e305a7dcf6 [Concurrency][Windows] Add a couple of includes for Windows.
Actor.cpp does need <io.h> still, and Task.cpp should have been including
<windows.h>

rdar://90776105
2022-06-07 07:39:52 +01:00
Alastair Houghton
14a4bd45b6 [Concurrency][Threading] Remove use of platform thread functions.
The concurrency library can use the new threading library functions,
which avoids the problem of including <windows.h>.

rdar://90776105
2022-06-07 07:39:52 +01:00
Alastair Houghton
66f6eb6bc6 [Runtime][Windows] A couple of files need to include <windows.h>
We shouldn't include <windows.h> implicitly from .cpp files, but should
do it directly so that we know it's there.

Also, if we're including <windows.h>, do it at the top of the file.

rdar://90776105
2022-06-07 07:39:52 +01:00
Alastair Houghton
05cccf939b [Runtime][Windows] Need to link with Synchronization.lib.
We're using some functions from Synchronization.lib now, after the
threading changes.

rdar://90776105
2022-06-07 07:39:52 +01:00
Alastair Houghton
f5bdb858e0 [Threading] Create new threading library and use it.
Moved all the threading code to one place.  Added explicit support for
Darwin, Linux, Pthreads, C11 threads and Win32 threads, including new
implementations of Once for Linux, Pthreads, C11 and Win32.

rdar://90776105
2022-06-07 07:39:51 +01:00
Alastair Houghton
0cf687aa2b [Build][Runtime] Replace SWIFT_STDLIB_SINGLE_THREADED_RUNTIME.
SWIFT_STDLIB_SINGLE_THREADED_RUNTIME is too much of a blunt instrument here.
It covers both the Concurrency runtime and the rest of the runtime, but we'd
like to be able to have e.g. a single-threaded Concurrency runtime while
the rest of the runtime is still thread safe (for instance).

So: rename it to SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY and make it just
control the Concurrency runtime, then add a SWIFT_STDLIB_THREADING_PACKAGE
setting at the CMake/build-script level, which defines
SWIFT_STDLIB_THREADING_xxx where xxx depends on the chosen threading package.

This is especially useful on systems where there may be a choice of threading
package that you could use.

rdar://90776105
2022-06-07 07:39:51 +01:00
Jager-yoo
ce6005d870 [Concurrency] fix grammatically incorrect phrase 2022-06-04 14:50:09 +09:00
Jager-yoo
3b8db192a0 [Gardening] fix typo "supercede" -> "supersede" 2022-05-29 03:35:24 +09:00
Yuta Saito
b6baa3fd2a Merge pull request #58514 from kateinoigakukun/katei/upstream-clock-cpp
[stdlib] Port SE-0329 Clock APIs to WASI
2022-05-26 22:02:07 +09:00
Alex Martini
5f2d5deb17 Back out spelling change.
Documentation follows Apple Style Guide spelling:

https://help.apple.com/applestyleguide/#/apsgb744e4a3#apdb51b39ece6204
2022-05-23 12:51:27 -07:00
Jager-yoo
b9bbe62006 [Concurrency] Revise Async- related files doc
- Revise '// Prints' comments style like the other stdlib files
- Remove verbose string interpolations and extra spaces
- Remove some unneeded parentheses
- Replace the majority of ' : ' with ': '
- Fix wrong indentation
- Keep files with a single empty line at the end
2022-05-16 14:55:27 +09:00
Doug Gregor
1a766782a8 Merge pull request #58906 from DougGregor/concurrency-fileid-not-file 2022-05-13 18:11:16 -07:00
Yuta Saito
f76552cf2b Merge pull request #42610 from kateinoigakukun/katei/coop-deadline-job
[Concurrency] Support duration-based sleep in cooperative executor
2022-05-14 09:55:22 +09:00
Doug Gregor
60c9fcbba6 [Concurrency] Use #fileID instead of #file so we don't get full paths.
Fixes rdar://93246032.
2022-05-13 15:07:04 -07:00
Kavon Farvardin
22323fbda9 correct format strings when building with SWIFT_TASK_DEBUG_LOG enabled 2022-05-10 13:00:45 -07:00
Karoy Lorentey
6d09bb0613 [stdlib] Adopt primary associated types in _Concurrency 2022-05-09 18:07:09 -07:00
Yuta Saito
7762867bb3 [Concurrency] Support duration-based sleep in cooperative executor 2022-05-08 07:08:00 +00:00
Jonathan Grynspan
b749dd395d Revert "runtime: allow over-aligned types in the runtime"
This reverts commit b694ce4634.
2022-05-05 11:10:12 -04:00
swift-ci
0cdbd3ea7a Merge pull request #42588 from mikeash/signpost-refinements
[Concurrency] Minor tweaks to continuation, task, and job tracing.
2022-04-29 08:44:35 -07: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
Karoy Lorentey
ff387aeebc Merge pull request #58411 from lorentey/fix-duration-warning
[stdlib] Fix warning on Clock.Duration
2022-04-26 17:13:24 -07:00
Karoy Lorentey
3136a4abd8 [stdlib] Fix warning on Clock.Duration
rdar://92306564
2022-04-25 18:29:10 -07:00
Jonathan Grynspan
7b630b3b17 Fix some build issues on Windows 2022-04-25 18:50:42 -04:00
Mike Ash
e5c61b3945 [Concurrency] Minor tweaks to continuation, task, and job tracing.
Change continuation signposts to emit an interval for init/resume.

Fix task_create to take the decoded flags as separate parameters, matching other calls.

Move job_run trace calls into runJobInEstablishedExecutorContext. swift_job_runImpl didn't catch everything.

rdar://92149411
2022-04-22 15:50:10 -04:00
Philippe Hausler
e12cc13c95 Move clock runtime functions to the same compliation build group as the task sleep build group (#42566) 2022-04-22 12:10:41 -07:00
Josh Soref
7a57e7ce99 Spelling stdlib/public/concurrency (#42443)
* spelling: already

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: appropriate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: asynchronous

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: cancel

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: divisible

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: execution

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialized

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: normally

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: preprocessed

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: priority

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: some

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: success

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: suspending

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: throws

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 11:12:57 -07:00
Rokhini Prabhu
d23c89b143 Merge pull request #42392 from rokhinip/rokhinip/90725051-switch-actors-to-OOL-jobs
Move Actor processing jobs to out-of-line jobs
2022-04-21 10:45:01 -07:00
Philippe Hausler
fd9f7140e2 Resolve a structural calculation error with clocks that prevented sleep to properly transmit to dispatch_after (#42518)
* Resolve a structural calculation error with clocks that prevented sleep to properly transmit to dispatch_after

* Remove dispatch dependency
2022-04-21 00:02:22 -07:00
Rokhini Prabhu
2c2aa05d47 Remove the inline job in actors and make them use OOL jobs always. This is because we need 16 bytes of atomic state in the actor which is not available to us on arm64_32 since the inline job takes up 40 of the 48 bytes for use.
Enable priority escalation support on arm64_32.

Radar-Id: rdar://problem/90725051
2022-04-15 11:30:03 -07:00