|
20 | 20 | #include "swift/ABI/TaskStatus.h"
|
21 | 21 |
|
22 | 22 | namespace swift {
|
| 23 | +class DefaultActor; |
23 | 24 |
|
24 | 25 | struct AsyncTaskAndContext {
|
25 | 26 | AsyncTask *Task;
|
@@ -206,6 +207,70 @@ swift_task_getNearestDeadline(AsyncTask *task);
|
206 | 207 | SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
|
207 | 208 | void swift_task_run(AsyncTask *taskToRun);
|
208 | 209 |
|
| 210 | +/// Switch the current task to a new executor if we aren't already |
| 211 | +/// running on a compatible executor. |
| 212 | +/// |
| 213 | +/// The resumption function pointer and continuation should be set |
| 214 | +/// appropriately in the task. |
| 215 | +/// |
| 216 | +/// Generally the compiler should inline a fast-path compatible-executor |
| 217 | +/// check to avoid doing the suspension work. This function should |
| 218 | +/// generally be tail-called, as it may continue executing the task |
| 219 | +/// synchronously if possible. |
| 220 | +SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swiftasync) |
| 221 | +void swift_task_switch(AsyncTask *task, |
| 222 | + ExecutorRef currentExecutor, |
| 223 | + ExecutorRef newExecutor); |
| 224 | + |
| 225 | +/// Enqueue the given job to run asynchronously on the given executor. |
| 226 | +/// |
| 227 | +/// The resumption function pointer and continuation should be set |
| 228 | +/// appropriately in the task. |
| 229 | +/// |
| 230 | +/// Generally you should call swift_task_switch to switch execution |
| 231 | +/// synchronously when possible. |
| 232 | +SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) |
| 233 | +void swift_task_enqueue(Job *job, ExecutorRef executor); |
| 234 | + |
| 235 | +/// Enqueue the given job to run asynchronously on the global |
| 236 | +/// execution pool. |
| 237 | +/// |
| 238 | +/// The resumption function pointer and continuation should be set |
| 239 | +/// appropriately in the task. |
| 240 | +/// |
| 241 | +/// Generally you should call swift_task_switch to switch execution |
| 242 | +/// synchronously when possible. |
| 243 | +SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) |
| 244 | +void swift_task_enqueueGlobal(Job *job); |
| 245 | + |
| 246 | +/// A hook to take over global enqueuing. |
| 247 | +/// TODO: figure out a better abstraction plan than this. |
| 248 | +SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) |
| 249 | +void (*swift_task_enqueueGlobal_hook)(Job *job); |
| 250 | + |
| 251 | +/// Initialize the runtime storage for a default actor. |
| 252 | +SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) |
| 253 | +void swift_defaultActor_initialize(DefaultActor *actor); |
| 254 | + |
| 255 | +/// Destroy the runtime storage for a default actor. |
| 256 | +SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) |
| 257 | +void swift_defaultActor_destroy(DefaultActor *actor); |
| 258 | + |
| 259 | +/// Enqueue a job on the default actor implementation. |
| 260 | +/// |
| 261 | +/// The job must be ready to run. Notably, if it's a task, that |
| 262 | +/// means that the resumption function and context should have been |
| 263 | +/// set appropriately. |
| 264 | +/// |
| 265 | +/// Jobs are assumed to be "self-consuming": once it starts running, |
| 266 | +/// the job memory is invalidated and the executor should not access it |
| 267 | +/// again. |
| 268 | +/// |
| 269 | +/// Jobs are generally expected to keep the actor alive during their |
| 270 | +/// execution. |
| 271 | +SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) |
| 272 | +void swift_defaultActor_enqueue(Job *job, DefaultActor *actor); |
| 273 | + |
209 | 274 | }
|
210 | 275 |
|
211 | 276 | #endif
|
0 commit comments