Commit Graph

109 Commits

Author SHA1 Message Date
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
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
Alex Hoppen
4aa2bbbf06 Revert "Merge pull request #42447 from al45tair/eng/PR-90776105"
This reverts commit 8bcb71140f, reversing
changes made to c4dd271d36.
2022-06-02 18:03:23 +02:00
Alastair Houghton
b5bd267ff1 [Threading] Put everything through git clang-format.
Just formatting changes.

rdar://90776105
2022-05-24 14:57:41 +01:00
Alastair Houghton
63a09007a1 [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-05-24 14:57:39 +01:00
Alastair Houghton
dadcb04ae2 [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-05-24 14:57:38 +01:00
Saleem Abdulrasool
a8b0ee24dc runtime: blanket application of namespacing and inclusion of new
Apply a blanket pass of including `new` for the placement new allocation
and namespacing the call to the global placement new allocator.  This
should repair the Android ARMv7 builds.
2022-04-14 14:21:12 -07:00
Rokhini Prabhu
a5fa349f88 Merge pull request #41281 from apple/rokhinip/88600541-task-priority-escalation-arm64_32
Task Escalation support on arm64_32 Apple platforms
2022-02-10 17:02:38 -08:00
Rokhini Prabhu
6beb11ed7d Rename flagAsEnqueuedOnExecutor to flagAsAndEnqueueOnExecutor to reflect
what it actually does.

Radar-Id: rdar://problem/88600541
2022-02-10 11:50:31 -08:00