Skip to content

Commit 09f3d99

Browse files
committed
[Concurrency] Add availability checking when calling voucher_needs_adopt from the SDK.
1 parent c4115cc commit 09f3d99

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

include/swift/Runtime/VoucherShims.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,18 @@
3939

4040
#if SWIFT_HAS_VOUCHERS
4141

42+
#if SWIFT_HAS_VOUCHER_HEADER
43+
44+
static inline bool swift_voucher_needs_adopt(voucher_t _Nullable voucher) {
45+
if (__builtin_available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *)) {
46+
return voucher_needs_adopt(voucher);
47+
}
48+
return true;
49+
}
50+
51+
#else
52+
4253
// If the header isn't available, declare the necessary calls here.
43-
#if !SWIFT_HAS_VOUCHER_HEADER
4454

4555
#include <os/object.h>
4656

@@ -54,7 +64,7 @@ extern "C" voucher_t _Nullable voucher_copy(void);
5464
// Consumes argument, returns retained value.
5565
extern "C" voucher_t _Nullable voucher_adopt(voucher_t _Nullable voucher);
5666

57-
static inline bool voucher_needs_adopt(voucher_t _Nullable voucher) {
67+
static inline bool swift_voucher_needs_adopt(voucher_t _Nullable voucher) {
5868
return true;
5969
}
6070

@@ -78,7 +88,7 @@ static inline voucher_t _Nullable voucher_copy(void) { return nullptr; }
7888
static inline voucher_t _Nullable voucher_adopt(voucher_t _Nullable voucher) {
7989
return nullptr;
8090
}
81-
static inline bool voucher_needs_adopt(voucher_t _Nullable voucher) {
91+
static inline bool swift_voucher_needs_adopt(voucher_t _Nullable voucher) {
8292
return true;
8393
}
8494
static inline void swift_voucher_release(voucher_t _Nullable voucher) {}

stdlib/public/Concurrency/VoucherSupport.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class VoucherManager {
4444
if (OriginalVoucher) {
4545
SWIFT_TASK_DEBUG_LOG("[%p] Restoring original voucher %p", this,
4646
*OriginalVoucher);
47-
if (voucher_needs_adopt(*OriginalVoucher)) {
47+
if (swift_voucher_needs_adopt(*OriginalVoucher)) {
4848
auto previous = voucher_adopt(*OriginalVoucher);
4949
swift_voucher_release(previous);
5050
} else {
@@ -67,7 +67,7 @@ class VoucherManager {
6767
assert(job->Voucher != SWIFT_DEAD_VOUCHER);
6868

6969
voucher_t previous;
70-
if (voucher_needs_adopt(job->Voucher)) {
70+
if (swift_voucher_needs_adopt(job->Voucher)) {
7171
// If we need to adopt the voucher, do so, and grab the old one.
7272
SWIFT_TASK_DEBUG_LOG("[%p] Swapping jobs to %p, adopting voucher %p",
7373
this, job, job->Voucher);
@@ -104,7 +104,7 @@ class VoucherManager {
104104
assert(OriginalVoucher);
105105
assert(task->Voucher == SWIFT_DEAD_VOUCHER);
106106

107-
if (voucher_needs_adopt(*OriginalVoucher)) {
107+
if (swift_voucher_needs_adopt(*OriginalVoucher)) {
108108
// Adopt the execution thread's original voucher. The task's voucher is
109109
// the one currently adopted, and is returned by voucher_adopt.
110110
task->Voucher = voucher_adopt(*OriginalVoucher);

0 commit comments

Comments
 (0)