Commit Graph

117 Commits

Author SHA1 Message Date
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
Konrad `ktoso` Malawski
2652862229 prepare for cancellation handling 2023-01-05 16:19:05 +09:00
Konrad `ktoso` Malawski
54dec38a34 initial complete impl 2023-01-05 16:19:05 +09:00
Konrad `ktoso` Malawski
f8b85015c1 prepare flags
wip on options

implement discardResults as a flag passed to grout init
2023-01-05 16:19:05 +09:00
Konrad `ktoso` Malawski
1a3403524c [Concurrency] Optimize Void task group, to not store completed tasks anymore 2023-01-05 16:19:05 +09:00
Erik Eckstein
525550644c concurrency runtime: fix unused variable/label warnings 2022-11-21 19:50:39 +01:00
John McCall
7f737d235d Synchronize with cancellation when removing a task from a task group
We were detaching the child by just modifying the list, but the cancellation path was assuming that that would not be done without holding the task status lock.

This patch just fixes the current runtime; the back-deployment side is complicated.

Fixes rdar://88398824
2022-10-29 00:10:28 -04:00
Rokhini Prabhu
a606892155 Task group children should be executed on parent task at time of await 2022-09-01 10:02:25 -07: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
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