Skip to content

Commit 2dc06c5

Browse files
committed
[Concurrency] Fix Dispatch linkage offset on 32-bit.
rdar://76703675
1 parent 7123d26 commit 2dc06c5

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

include/swift/ABI/Task.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,18 @@ class alignas(2 * alignof(void*)) Job : public HeapObject {
4646
/// The next waiting task link, an AsyncTask that is waiting on a future.
4747
NextWaitingTaskIndex = 0,
4848

49+
// The Dispatch object header is one pointer and two ints, which is
50+
// equvialent to three pointers on 32-bit and two pointers 64-bit. Set the
51+
// indexes accordingly so that DispatchLinkageIndex points to where Dispatch
52+
// expects.
53+
DispatchHasLongObjectHeader = sizeof(void *) == sizeof(int),
54+
4955
/// An opaque field used by Dispatch when enqueueing Jobs directly.
50-
DispatchLinkageIndex = 0,
56+
DispatchLinkageIndex = DispatchHasLongObjectHeader ? 1 : 0,
5157

5258
/// The dispatch queue being used when enqueueing a Job directly with
5359
/// Dispatch.
54-
DispatchQueueIndex = 1,
60+
DispatchQueueIndex = DispatchHasLongObjectHeader ? 0 : 1,
5561
};
5662

5763
// Reserved for the use of the scheduler.

stdlib/public/Concurrency/GlobalExecutor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ void swift::donateThreadToGlobalExecutorUntil(bool (*condition)(void *),
190190
// not complete and should not be used for anything other than these asserts.
191191
struct MinimalDispatchObjectHeader {
192192
const void *VTable;
193-
void *Opaque;
193+
int Opaque0;
194+
int Opaque1;
194195
void *Linkage;
195196
};
196197
static_assert(

0 commit comments

Comments
 (0)