Commit Graph

126 Commits

Author SHA1 Message Date
Kuba Mracek
d2dac4ed72 [Concurrency] Avoid relying on stderr, fprintf(), write() in Embedded Concurrency runtime 2024-10-14 13:36:14 -07:00
Alastair Houghton
54a495527e [Concurrency] Remove C++ runtime references from embedded Concurrency.
In embedded mode, we mustn't have references to the C++ library, because
some embedded platforms don't include the C++ library.

Additionally, it's good to avoid use of global operator new and operator
delete, because they can be globally overridden and this has bitten us
in the past.

rdar://137286187
2024-10-07 10:30:27 +01:00
Kuba (Brecka) Mracek
341d6305ff Merge pull request #76767 from kubamracek/embedded-concurrency-task-groups
[Concurrency] Enable TaskGroup/DiscardingTaskGroup in Embedded Swift
2024-10-03 19:29:54 -07:00
Michael Gottesman
cb8e8b505a Fix syntax highlighting by changing how we include COMPATIBILITY_OVERRIDE_INCLUDE_PATH.
The way that we include COMPATIBILITY_OVERRIDE_INCLUDE_PATH freaks out the
syntax highlighting of editors like emacs. It causes the whole file to be
highlighted like it is part of the include string.

To work around this, this patch creates a separate file called
CompatibilityOverrideIncludePath.h that just includes
COMPATIBILITY_OVERRIDE_INCLUDE_PATH. So its syntax highlighting is borked, but
at least in the actual files that contain real code, the syntax highlighting is
restored.
2024-10-01 16:17:16 -07:00
Kuba Mracek
a2dcb6045c [embedded] Introduce a new swift_taskGroup_initializeWithOptions runtime entrypoint 2024-10-01 14:56:38 -07:00
Kuba Mracek
f1c2334c9a [Concurrency] Enable TaskGroup/DiscardingTaskGroup in Embedded Swift 2024-09-28 17:52:05 -07:00
Rose
ea2b116764 Specify atomicity for compare_exchange_strong
waitQueue only needs to atomically be set to nullptr
2024-08-18 18:28:45 -04:00
Konrad `ktoso` Malawski
3c75f2fac8 Add comment explaining #if guard 2024-07-08 10:49:38 +09:00
Yuta Saito
49a20d110a Concurrency: Guard TG state with a mutex even with cooperative executor
`SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY` just means that the global
executor is cooperative, but it doesn't mean that the target platform is
always single-threaded. For example, on wasm32-unknown-wasip1-threads,
the global executor is cooperative, but users can still set up their own
TaskExecutor with multiple threads.

This patch guards the `TaskGroup` state with a mutex even with a
cooperative executor by respecting threading package instead. This
change effectively affects only wasm32-unknown-wasip1-threads.
2024-07-06 08:14:07 +00:00
Allan Shortlidge
92a0867f08 Merge pull request #70948 from tshortli/resolve-concurrency-runtime-warnings
Resolve warnings in the Concurrency runtime
2024-01-16 18:59:50 -08:00
Allan Shortlidge
f18b196ed8 NFC: Suppress a -Wunreachable-code warning in GlobalExecutor.cpp.
The `swift_unreachable()` is currently statically unreachable but we'd like to
leave it in place in case the control flow before it changes in the future.
2024-01-16 16:21:06 -08:00
Allan Shortlidge
79d0ecafaa NFC: Ignore deprecation of asl_log in the runtime and demangling library.
ASL is deprecated in macOS 10.12. It may be time to transition to os_log now
that deployment targets have been raised to 10.12, but until that project
starts these warnings are just pollution.

Filed rdar://121066531 to track adoption of `os_log()` if appropriate.
2024-01-16 13:27:55 -08:00
AtariDreams
e2d2ca05d6 waitQueue.compare_exchange_strong in the true loop can be weak (#70636) 2024-01-09 16:49:43 +09:00
Rokhini Prabhu
ffd1ad2286 Convert use of std::mutex in task groups to use Mutex from threading package
Radar-Id: rdar://problem/119415891
2023-12-08 20:17:52 -08:00
Konrad `ktoso` Malawski
5546f4da7b Rename ExecutorRef to SerialExecutorRef 2023-11-01 18:39:44 +09:00
Kuba Mracek
744f558e9c [embedded] Don't allow ResultTypeInfoTaskOptionRecord parsing outside embedded Swift 2023-10-06 20:04:03 -07:00
Kuba Mracek
5d8c55eacb [embedded] Initial Swift Concurrency for embedded Swift 2023-10-06 20:04:03 -07:00
Konrad `ktoso` Malawski
1195955647 Review feedback: add better code comments 2023-08-10 21:16:09 +09:00
Konrad `ktoso` Malawski
8aa70dc733 cleanup for freestanding mode 2023-08-09 13:08:04 +09:00
Konrad `ktoso` Malawski
7d93bba7df cleanups 2023-08-09 12:47:01 +09:00
Konrad `ktoso` Malawski
060260e959 make use of unreachable 2023-08-09 08:44:12 +09:00
Konrad `ktoso` Malawski
383c62f731 disable debugging tricks 2023-08-09 08:44:12 +09:00
Konrad `ktoso` Malawski
61d783c5b3 revamping locking scheme, test this a bunch 2023-08-09 08:44:11 +09:00
Konrad `ktoso` Malawski
b135ecd8f6 [TaskGroup] Must detach discarded task, THEN unlock before resume waiting 2023-08-09 08:44:11 +09:00
Konrad `ktoso` Malawski
9d9f8cb143 [DiscardingTaskGroup] Properly detach when LAST task is failed, and prior failure was already stored 2023-08-09 08:44:11 +09:00
Konrad `ktoso` Malawski
d01abcb42e Unlock BEFORE resuming the waitAll waiting task, to avoid unlock() on
released memory.

Because the waitAll() group method is called before the group returns
from withTaskGroup and is used to ensure all tasks have completed before
we destroy the task group, this method is then immediately followed by
calling TaskGroup::destroy.

If we, as previously, first resume the waiting task and then attempt to
unlock the lock held by the group, we are in an unsafe situation with
racing the task group destroy() and the unlock().

Therefore, we must release the lock before we resume the waiting task.
2023-08-04 08:46:30 +09:00
Konrad `ktoso` Malawski
6bfef94c9e [docs][Concurrency] Include required parameter in group docs
[docs][Concurrency] Fix typo in method signature in code snippets of groups
2023-06-30 12:17:57 +09:00
Konrad `ktoso` Malawski
760cb44987 remove extra debug statements 2023-05-24 18:59:18 +02:00
Konrad `ktoso` Malawski
9f5a707a30 back to println tests 2023-05-24 18:03:46 +02:00
Konrad `ktoso` Malawski
cad608eb81 [Discarding] Don't leak retained "first error" task when retaining it 2023-05-24 18:03:28 +02:00
Rokhini Prabhu
d0aa55670a Provide an updateStatusRecord function which allows clients to update a
status record that is already registered with the task. Provide more
versatile removeStatusRecord functions and update clients to use them

Radar-Id: rdar://problem/101864092
2023-02-25 16:55:38 -08:00
Rokhini Prabhu
3c0f4f79fe Provide a convenience for addStatusRecord for clients who have already
done the load or who need the oldStatus information after adding the
status record.

Change some of the memory barrier logic since we can take advantage of
load-through HW address dependency.

Radar-Id: rdar://problem/105634683
2023-02-20 23:14:47 -08:00
Konrad `ktoso` Malawski
965c963fbd [Concurrency] Memory order of success must be >= failure path in exchange (#63732) 2023-02-17 12:47:44 +09:00
Rokhini Prabhu
babaa4bc2a Merge pull request #63019 from apple/rokhinip/88093007-priority-escalation-to-future
Provide support for live priority escalation in the task runtime
2023-02-11 11:33:41 -08:00
Rokhini Prabhu
e052ccef31 Create the notion of a TaskDependencyStatusRecord which tracks what a
task is blocked on. We can use this information to then perform live
priority escalation to a task future.

Radar-Id: rdar://problem/88093007
2023-02-08 17:29:55 -08:00
Rokhini Prabhu
2e6baf279d Add support to addStatusRecord and removeStatusRecord so that the flags
field of an ActiveTaskStatus can also be modified while the
TaskStatusRecord list is being modified. Make the StatusRecordLock
reentrant.

Radar-Id: rdar://problem/88093007
2023-02-08 17:29:05 -08:00
Dario Rexin
961125320a [Concurrency] Make error logging more robust (#63383)
rdar://104967560
2023-02-03 11:48:47 -08:00
Dario Rexin
a9b69a14c5 [Concurrency] Add include of unistd.h to TaskGroup.cpp (#63265)
* [Concurrency] Add include of unistd.h to TaskGroup.cpp

rdar://104758975

Missing import caused build failures:

```
stdlib/public/Concurrency/TaskGroup.cpp:572:11: error: use of undeclared identifier 'STDERR_FILENO'
    write(STDERR_FILENO, message, strlen(message));
          ^
```

* Update TaskGroup.cpp

* Add missing _enqueue method in SWIFT_CONCURRENCY_TASK_TO_THREAD_MODEL mode

---------

Co-authored-by: Konrad `ktoso` Malawski <ktoso@apple.com>
2023-01-31 09:43:58 -08:00
Konrad `ktoso` Malawski
99fb37f678 [Concurrency] Fix too optimistic TaskGroup bail-out-when-empty, (#63016)
* [Concurrency] Fix too optimistic bail-out-when-empty, discarding group
may need to emit an error out of such waitAll attempt, if a previous
error was already stored.

* [Concurrency] DiscardingTG error thrown from body always wins

* Offering body error must be done while holding lock

* Must not modify waitingTask context outside lock

* wip on trying to fix by changing the offer

* fix bug in resuming tasks in offer/resume task in discarding group

* Fix #63147 waitForAll impl in ThrowingTaskGroup, used to not wait enough

rdar://104507347

* done

* debug

* explicitly declare virtual destructors

* detach child task after filling result; dont mutate context outside of lock

* Add pending count overflow protection to TaskGroup

* unlock async_taskgroup_void_neverConsumingTasks again rdar://104332560

* missing include on windows for error reporting

* fix ARM_ARCH_7K workaround snippet
2023-01-27 19:00:26 +09:00
Konrad `ktoso` Malawski
53682358d0 [Concurrency] Fix DiscardingTaskGroup in TASK_TO_THREAD (#63009) 2023-01-13 22:57:33 +09:00
Konrad `ktoso` Malawski
4b90cdbe5c Revert "cleanup"
This reverts commit 128e2b2099.
2023-01-11 13:03:22 +09:00
Konrad `ktoso` Malawski
128e2b2099 cleanup 2023-01-11 12:40:25 +09:00
Konrad `ktoso` Malawski
6d63cf4994 fix cast type in getting task record 2023-01-11 11:55:52 +09:00
Konrad `ktoso` Malawski
6f33f2af88 remove even more duplicated methods 2023-01-09 14:42:43 +09:00
Konrad `ktoso` Malawski
f09cef20d9 more cleanup 2023-01-09 14:09:13 +09:00
Konrad `ktoso` Malawski
7845de85c7 remove duplicated status logic 2023-01-09 13:18:23 +09:00
Konrad `ktoso` Malawski
6f38910058 DiscardingTaskGroup now shares some implementation with "Accumulating" TaskGroup 2023-01-09 11:35:04 +09:00
Konrad `ktoso` Malawski
e37b998c56 implement simple rethrowing logic, however body throw always wins 2023-01-05 21:42:20 +09:00
Konrad `ktoso` Malawski
2eaaf352de complete impl, except body throws 2023-01-05 20:13:05 +09:00
Konrad `ktoso` Malawski
7ac5b407a6 move to DiscardingTaskGroup 2023-01-05 16:19:05 +09:00