Commit Graph

71 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
3d96d05546 [TaskLocals] property wrapper keys 2021-04-29 15:48:09 +09:00
Mike Ash
6aab257c33 [Concurrency] Add compatibility overrides to Concurrency library.
Take the existing CompatibilityOverride mechanism and generalize it so it can be used in both the runtime and Concurrency libraries. The mechanism is preprocessor-heavy, so this requires some tricks. Use the SWIFT_TARGET_LIBRARY_NAME define to distinguish the libraries, and use a different .def file and mach-o section name accordingly.

We want the global/main executor functions to be a little more flexible. Instead of using the override mechanism, we expose function pointers that can be set by the compatibility library, or by any other code that wants to use a custom implementation.

rdar://73726764
2021-03-22 11:09:06 -04:00
John McCall
6c879d6fd3 Change the async ABI to not pass the active task and executor.
Most of the async runtime functions have been changed to not
expect the task and executor to be passed in.  When knowing the
task and executor is necessary, there are runtime functions
available to recover them.

The biggest change I had to make to a runtime function signature
was to swift_task_switch, which has been altered to expect to be
passed the context and resumption function instead of requiring
the caller to park the task.  This has the pleasant consequence
of allowing the implementation to very quickly turn around when
it recognizes that the current executor is satisfactory.  It does
mean that on arm64e we have to sign the continuation function
pointer as an argument and then potentially resign it when
assigning into the task's resume slot.

rdar://70546948
2021-03-16 22:52:54 -04:00
Konrad `ktoso` Malawski
aedbbe615d [TaskGroup] Towards ABI stability of groups 2021-03-02 20:25:22 +09:00
Konrad `ktoso` Malawski
fbaebfd79b [Concurrency] Escalating task groups, type fix, group record IS-NOT a child record 2021-02-22 13:26:38 +09:00
Konrad `ktoso` Malawski
07d6715d9f cleanup: remove all println debugging from task infra 2021-02-22 13:26:38 +09:00
Konrad `ktoso` Malawski
3132009929 [Concurrency] Track group children in task record + invasive links 2021-02-22 13:26:33 +09:00
Konrad `ktoso` Malawski
1c4655df6a [Concurrency] track child tasks from group in Task records 2021-02-22 13:26:33 +09:00
Konrad `ktoso` Malawski
efc7d8e627 [Concurrency] rearrange layout of AsyncTask now that task locals and groups coexist 2021-02-22 13:26:33 +09:00
Konrad `ktoso` Malawski
b1e5c4a2c4 test cleanups, additional test to check we dont cancel other groups 2021-02-22 13:26:28 +09:00
Konrad `ktoso` Malawski
1860b20cb7 [Concurrency] cancel all child tasks of a group on cancelAll 2021-02-22 13:26:27 +09:00
Konrad `ktoso` Malawski
a368aa1872 [Concurrency] store child record, cancellation works; async_task_cancellation 2021-02-22 13:26:27 +09:00
Konrad `ktoso` Malawski
edbcb1ea9e [Concurrency] task cancellation propagate through children 2021-02-22 13:26:27 +09:00
Konrad `ktoso` Malawski
80ee936a72 Revert "[Concurrency] isCanceled spelling to follow guidance" 2021-01-23 07:27:34 +09:00
Konrad `ktoso` Malawski
8b37455774 [Concurrency] isCanceled spelling to follow guidance 2021-01-22 12:09:19 +09:00
Mike Ash
768a085de8 Merge pull request #34598 from mikeash/os-unfair-lock-mutex
[Runtime] Use os_unfair_lock for Mutex and StaticMutex on Darwin.
2020-11-11 11:37:12 -05:00
Mike Ash
e82d9e8c7b Move ConditionMutex to ConditionVariable::Mutex and move various other Mutex.h types to be nested. 2020-11-10 14:44:59 -05:00
Mike Ash
dd6c235a2d [Runtime] Use os_unfair_lock for Mutex and StaticMutex on Darwin.
os_unfair_lock is much smaller than pthread_mutex_t (4 bytes versus 64) and a bit faster.

However, it doesn't support condition variables. Most of our uses of Mutex don't use condition variables, but a few do. Introduce ConditionMutex and StaticConditionMutex, which allow condition variables and continue to use pthread_mutex_t.

On all other platforms, we continue to use the same backing mutex type for both Mutex and ConditionMutex.

rdar://problem/45412121
2020-11-06 13:05:37 -05:00
Doug Gregor
c291eb596b [Concurrency] Add cancelAsyncTask() builtin.
Implement a new builtin, `cancelAsyncTask()`, to cancel the given
asynchronous task. This lowers down to a call into the runtime
operation `swift_task_cancel()`.

Use this builtin to implement Task.Handle.cancel().
2020-11-05 13:50:17 -08:00
John McCall
c18331c837 Move swift_task_alloc/dealloc into the Concurrency library.
Also, rename them to follow the general namespacing scheme.
2020-10-22 00:53:15 -04:00
John McCall
8ac4362754 Implement a simple library for task cancellation and status management.
There are things about this that I'm far from sold on.  In
particular, I'm concerned that in order to implement escalation
correctly, we're going to have to add a status record for the
fact that the task is being executed, which means we're going
to have to potentially wait to acquire the status lock; overall,
that means making an extra runtime function call and doing some
atomics whenever we resume or suspend a task, which is an
uncomfortable amount of overhead.

The testing here is pretty grossly inadequate, but I wanted to
lay down the groundwork here.
2020-10-15 00:36:36 -04:00