File tree Expand file tree Collapse file tree 2 files changed +10
-12
lines changed
stdlib/public/Concurrency Expand file tree Collapse file tree 2 files changed +10
-12
lines changed Original file line number Diff line number Diff line change @@ -482,25 +482,23 @@ class AsyncTask : public Job {
482
482
483
483
// / Retrieve a pointer to the storage of result.
484
484
OpaqueValue *getStoragePtr () {
485
+ auto *startAddr = reinterpret_cast <char *>(this ) + sizeof (FutureFragment);
486
+ uintptr_t startAddrVal = (uintptr_t )startAddr;
487
+ uintptr_t alignment = resultType->vw_alignment ();
488
+ startAddrVal = (startAddrVal + alignment -1 ) & ~(alignment -1 );
485
489
return reinterpret_cast <OpaqueValue *>(
486
- reinterpret_cast <char *>(this ) + storageOffset (resultType ));
490
+ reinterpret_cast <char *>(startAddrVal ));
487
491
}
488
492
489
493
// / Retrieve the error.
490
494
SwiftError *&getError () { return error; }
491
495
492
- // / Compute the offset of the storage from the base of the future
493
- // / fragment.
494
- static size_t storageOffset (const Metadata *resultType) {
495
- size_t offset = sizeof (FutureFragment);
496
- size_t alignment = resultType->vw_alignment ();
497
- return (offset + alignment - 1 ) & ~(alignment - 1 );
498
- }
499
-
500
496
// / Determine the size of the future fragment given a particular future
501
497
// / result type.
502
- static size_t fragmentSize (const Metadata *resultType) {
503
- return storageOffset (resultType) + resultType->vw_size ();
498
+ static size_t fragmentSize (size_t initialOffset, const Metadata *resultType) {
499
+ size_t alignment = resultType->vw_alignment ();
500
+ size_t padding = alignment - ((sizeof (FutureFragment) + initialOffset) % alignment);
501
+ return sizeof (FutureFragment) + padding + resultType->vw_size ();
504
502
}
505
503
};
506
504
Original file line number Diff line number Diff line change @@ -513,7 +513,7 @@ static AsyncTaskAndContext swift_task_create_commonImpl(
513
513
headerSize += sizeof (AsyncTask::GroupChildFragment);
514
514
}
515
515
if (futureResultType) {
516
- headerSize += FutureFragment::fragmentSize (futureResultType);
516
+ headerSize += FutureFragment::fragmentSize (headerSize, futureResultType);
517
517
// Add the future async context prefix.
518
518
headerSize += sizeof (FutureAsyncContextPrefix);
519
519
} else {
You can’t perform that action at this time.
0 commit comments