@@ -88,6 +88,13 @@ class AsyncFunctionPointer {
88
88
89
89
// / A schedulable job.
90
90
class alignas (2 * alignof (void *)) Job {
91
+ protected:
92
+ // Indices into SchedulerPrivate, for use by the runtime.
93
+ enum {
94
+ // / The next waiting task link, an AsyncTask that is waiting on a future.
95
+ NextWaitingTaskIndex = 0 ,
96
+ };
97
+
91
98
public:
92
99
// Reserved for the use of the scheduler.
93
100
void *SchedulerPrivate[2 ];
@@ -190,16 +197,12 @@ class AsyncTask : public HeapObject, public Job {
190
197
// / Reserved for the use of the task-local stack allocator.
191
198
void *AllocatorPrivate[4 ];
192
199
193
- // / The next task in the linked list of waiting tasks.
194
- AsyncTask *NextWaitingTask;
195
-
196
200
AsyncTask (const HeapMetadata *metadata, JobFlags flags,
197
201
TaskContinuationFunction *run,
198
202
AsyncContext *initialContext)
199
203
: HeapObject(metadata), Job(flags, run),
200
204
ResumeContext (initialContext),
201
- Status(ActiveTaskStatus()),
202
- NextWaitingTask(nullptr ) {
205
+ Status(ActiveTaskStatus()) {
203
206
assert (flags.isAsyncTask ());
204
207
}
205
208
@@ -265,9 +268,9 @@ class AsyncTask : public HeapObject, public Job {
265
268
// / head of the list of tasks.
266
269
struct WaitQueueItem {
267
270
// / Mask used for the low status bits in a wait queue item.
268
- const uintptr_t statusMask = 0x03 ;
271
+ static const uintptr_t statusMask = 0x03 ;
269
272
270
- uintptr_t storage;
273
+ const uintptr_t storage;
271
274
272
275
Status getStatus () const {
273
276
return static_cast <Status>(storage & statusMask);
@@ -359,13 +362,20 @@ class AsyncTask : public HeapObject, public Job {
359
362
// / executor.
360
363
void completeFuture (AsyncContext *context, ExecutorRef executor);
361
364
365
+ // / Access the next waiting task, which establishes a singly linked list of
366
+ // / tasks that are waiting on a future.
367
+ AsyncTask *&getNextWaitingTask () {
368
+ return reinterpret_cast <AsyncTask *&>(
369
+ SchedulerPrivate[NextWaitingTaskIndex]);
370
+ }
371
+
362
372
static bool classof (const Job *job) {
363
373
return job->isAsyncTask ();
364
374
}
365
375
};
366
376
367
377
// The compiler will eventually assume these.
368
- static_assert (sizeof (AsyncTask) == 14 * sizeof(void *),
378
+ static_assert (sizeof (AsyncTask) == 12 * sizeof(void *),
369
379
"AsyncTask size is wrong");
370
380
static_assert (alignof (AsyncTask) == 2 * alignof(void *),
371
381
"AsyncTask alignment is wrong");
0 commit comments