Commit Graph

163 Commits

Author SHA1 Message Date
Joe Groff
185f44e2d3 Concurrency: Implement resume(returning:) and resume(throwing:) for Unsafe*Continuation. 2020-12-07 07:47:47 -08:00
Doug Gregor
105a27322d [Concurrency] Traffic in underlying C type rather than JobFlags.
Suppresses a warning about returning a C++ type from a C entrypoint,
fixing rdar://71731181.
2020-12-04 12:29:18 -08:00
John McCall
853a8657dd Add a basic default-actor implementation with support for
eagerly adopting and abandoning threads.
2020-12-02 18:47:02 -05:00
Konrad `ktoso` Malawski
7126f32f22 fix properly, by using Task.JobFlags which does conversions 2020-11-20 00:46:40 -08:00
Konrad `ktoso` Malawski
261f0d2dcd +task Implement Task.currentPriority 2020-11-20 09:00:41 +09:00
Doug Gregor
894528062d [Concurrency] Implement Task.Handle.get() in terms of an async runtime call.
Switch the contract between the runtime operation `swift_future_task_wait`
and Task.Handle.get() pver to an asynchronous call, so that the
compiler will set up the resumption frame for us. This allows us to
correctly wait on futures.

Update our "basic" future test to perform both normal returns and
throwing returns from a future, either having to wait on the queue or
coming by afterward.
2020-11-18 22:02:14 -08:00
Doug Gregor
7f3db7fbde [Concurrency] Have future functions write their results directly.
Introduce `FutureAsyncContext` to line up with the async context formed
by IR generation for the type `<T> () async throws -> T`. When allocating
a future task, set up the context with the address of the future's storage
for the successful result and null out the error result, so the caller
will directly fill in the result. This eliminates a bunch of extra
complexity and a copy.
2020-11-14 15:18:54 -08:00
Doug Gregor
4b924673ce [Concurrency] Use a single atomic for future wait queue.
Use a single atomic for the wait queue that combines the status with
the first task in the queue. Address race conditions in waiting and
completing the future.

Thanks to John for setting the direction here for me.
2020-11-14 15:18:54 -08:00
Doug Gregor
85d003ef9b [Concurrency] Implement basic runtime support for task futures.
Extend AsyncTask and the concurrency runtime with basic support for
task futures. AsyncTasks with futures contain a future fragment with
information about the type produced by the future, and where the
future will put the result value or the thrown error in the initial
context.

We still don't have the ability to schedule the waiting tasks on an
executor when the future completes, so this isn't useful for anything
just test, and we can only test limited code paths.
2020-11-14 15:18:54 -08:00
Arnold Schwaighofer
193a3d5a8f Temporarily add runAsync to run a task synchronously in the current thread
Add a temporary runtime entry to run a task synchronous.
2020-11-13 10:41:42 -08:00
John McCall
a06d18ce81 Add API for creating unscheduled tasks.
Make all tasks into heap objects.
2020-10-22 00:53:16 -04: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