Implement continuations in task-to-thread model.

This is done using a condition variable upon which the awaiting thread
will block if the continuation has not be resumed by the point of await.
The resuming thread will signal this condition variable, thereby
unblocking the awaiting thread.

Rdar://99977665
This commit is contained in:
Rokhini Prabhu
2022-10-14 08:54:15 -07:00
parent 94b17595ee
commit b2f51dd3de
5 changed files with 175 additions and 23 deletions

View File

@@ -690,14 +690,28 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
*this, "swift.async_task_and_context",
{ SwiftTaskPtrTy, SwiftContextPtrTy });
ContinuationAsyncContextTy = createStructType(
*this, "swift.continuation_context",
{SwiftContextTy, // AsyncContext header
SizeTy, // flags
SizeTy, // await synchronization
ErrorPtrTy, // error result pointer
OpaquePtrTy, // normal result address
SwiftExecutorTy}); // resume to executor
if (Context.LangOpts.isConcurrencyModelTaskToThread()) {
ContinuationAsyncContextTy = createStructType(
*this, "swift.continuation_context",
{SwiftContextTy, // AsyncContext header
SizeTy, // flags
SizeTy, // await synchronization
ErrorPtrTy, // error result pointer
OpaquePtrTy, // normal result address
SwiftExecutorTy, // resume to executor
SizeTy // pointer to condition variable
});
} else {
ContinuationAsyncContextTy = createStructType(
*this, "swift.continuation_context",
{SwiftContextTy, // AsyncContext header
SizeTy, // flags
SizeTy, // await synchronization
ErrorPtrTy, // error result pointer
OpaquePtrTy, // normal result address
SwiftExecutorTy // resume to executor
});
}
ContinuationAsyncContextPtrTy =
ContinuationAsyncContextTy->getPointerTo(DefaultAS);