Skip to content

Commit 04106fb

Browse files
authored
Merge pull request #65760 from DougGregor/fix-back-deploy-dawn-of-concurrency-time-5.8
2 parents 9b59cbe + a9dacaf commit 04106fb

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

stdlib/toolchain/Compatibility56/Concurrency/Actor.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include "swift/Runtime/Casting.h"
99
#include "Runtime/Threading/ThreadLocal.h"
1010

11+
#include <Availability.h>
12+
#include <TargetConditionals.h>
13+
1114
#include <atomic>
1215
#include <new>
1316

@@ -146,3 +149,47 @@ void swift::adoptTaskVoucher(AsyncTask *task) {
146149
void swift::restoreTaskVoucher(AsyncTask *task) {
147150
ExecutorTrackingInfo::current()->restoreVoucher(task);
148151
}
152+
153+
static swift_once_t voucherDisableCheckOnce;
154+
static bool vouchersDisabled;
155+
156+
namespace {
157+
struct _SwiftNSOperatingSystemVersion{
158+
intptr_t majorVersion;
159+
intptr_t minorVersion;
160+
intptr_t patchVersion;
161+
};
162+
}
163+
164+
extern "C"
165+
_SwiftNSOperatingSystemVersion
166+
_swift_stdlib_operatingSystemVersion() __attribute__((const));
167+
168+
static void _initializeVouchersDisabled(void *ctxt) {
169+
auto osVersion = _swift_stdlib_operatingSystemVersion();
170+
#if TARGET_OS_WATCH
171+
vouchersDisabled = (
172+
osVersion.majorVersion == 8 &&
173+
osVersion.minorVersion >= 0 && osVersion.minorVersion < 3
174+
);
175+
#elif TARGET_OS_IPHONE
176+
vouchersDisabled = (
177+
osVersion.majorVersion == 15 &&
178+
osVersion.minorVersion >= 0 && osVersion.minorVersion < 2
179+
);
180+
#elif TARGET_OS_OSX
181+
vouchersDisabled = (
182+
osVersion.majorVersion == 12 &&
183+
osVersion.minorVersion >= 0 && osVersion.minorVersion < 1
184+
);
185+
#else
186+
vouchersDisabled = false;
187+
#endif
188+
}
189+
190+
bool VoucherManager::vouchersAreDisabled() {
191+
swift_once(&voucherDisableCheckOnce,
192+
&_initializeVouchersDisabled,
193+
nullptr);
194+
return vouchersDisabled;
195+
}

stdlib/toolchain/Compatibility56/include/Concurrency/VoucherSupport.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ class VoucherManager {
3131
/// async work.
3232
llvm::Optional<voucher_t> OriginalVoucher;
3333

34+
/// Determine whether vouchers are disabled entirely. This evaluates
35+
/// true on platforms whose concurrency library does not support the
36+
/// propagation of vouchers, in which case all of the operations of
37+
/// this class must be no-ops.
38+
static bool vouchersAreDisabled();
39+
3440
public:
3541
VoucherManager() {
3642
SWIFT_TASK_DEBUG_LOG("[%p] Constructing VoucherManager", this);
@@ -41,6 +47,9 @@ class VoucherManager {
4147
/// VoucherManager object is destroyed. It may also be called in other
4248
/// places to restore the original voucher and reset the VoucherManager.
4349
void leave() {
50+
if (vouchersAreDisabled())
51+
return;
52+
4453
if (OriginalVoucher) {
4554
SWIFT_TASK_DEBUG_LOG("[%p] Restoring original voucher %p", this,
4655
*OriginalVoucher);
@@ -62,6 +71,9 @@ class VoucherManager {
6271
/// this is permanent. For Tasks, the voucher must be restored using
6372
/// restoreVoucher if the task suspends.
6473
void swapToJob(Job *job) {
74+
if (vouchersAreDisabled())
75+
return;
76+
6577
SWIFT_TASK_DEBUG_LOG("[%p] Swapping jobs to %p", this, job);
6678
assert(job);
6779
assert(job->Voucher != SWIFT_DEAD_VOUCHER);
@@ -99,6 +111,9 @@ class VoucherManager {
99111
// Take the current thread's adopted voucher and place it back into the task
100112
// that previously owned it, re-adopting the thread's original voucher.
101113
void restoreVoucher(AsyncTask *task) {
114+
if (vouchersAreDisabled())
115+
return;
116+
102117
SWIFT_TASK_DEBUG_LOG("[%p] Restoring %svoucher on task %p", this,
103118
OriginalVoucher ? "" : "missing ", task);
104119
assert(OriginalVoucher);

0 commit comments

Comments
 (0)