-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Concurrency] Propagate Darwin vouchers across async tasks. #39115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
//===--- VoucherShims.h - Shims for OS vouchers --------------------*- C++ -*-// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Shims for interfacing with OS voucher calls. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef SWIFT_CONCURRENCY_VOUCHERSHIMS_H | ||
#define SWIFT_CONCURRENCY_VOUCHERSHIMS_H | ||
|
||
#include "Config.h" | ||
|
||
// swift-corelibs-libdispatch has os/voucher_private.h but it doesn't work for | ||
// us yet, so only look for it on Apple platforms. | ||
#if __APPLE__ && __has_include(<os/voucher_private.h>) | ||
#define SWIFT_HAS_VOUCHER_HEADER 1 | ||
#include <os/voucher_private.h> | ||
#endif | ||
|
||
// A "dead" voucher pointer, indicating that a voucher has been removed from | ||
// a Job, distinct from a NULL voucher that could just mean no voucher was | ||
// present. This allows us to catch problems like adopting a voucher from the | ||
// same Job twice without restoring it. | ||
#define SWIFT_DEAD_VOUCHER ((voucher_t)-1) | ||
|
||
// The OS has voucher support if it has the header or if it has ObjC interop. | ||
#if SWIFT_HAS_VOUCHER_HEADER || SWIFT_OBJC_INTEROP | ||
#define SWIFT_HAS_VOUCHERS 1 | ||
#endif | ||
|
||
#if SWIFT_HAS_VOUCHERS | ||
|
||
// If the header isn't available, declare the necessary calls here. | ||
#if !SWIFT_HAS_VOUCHER_HEADER | ||
|
||
#include <os/object.h> | ||
|
||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" | ||
OS_OBJECT_DECL_CLASS(voucher); | ||
#pragma clang diagnostic pop | ||
|
||
extern "C" voucher_t _Nullable voucher_copy(void); | ||
|
||
// Consumes argument, returns retained value. | ||
extern "C" voucher_t _Nullable voucher_adopt(voucher_t _Nullable voucher); | ||
|
||
static inline bool voucher_needs_adopt(voucher_t _Nullable voucher) { | ||
return true; | ||
} | ||
|
||
#endif // __has_include(<os/voucher_private.h>) | ||
|
||
static inline void swift_voucher_release(voucher_t _Nullable voucher) { | ||
// This NULL check isn't necessary, but NULL vouchers will be common, so | ||
// optimize for that. | ||
if (!voucher) | ||
return; | ||
if (voucher == SWIFT_DEAD_VOUCHER) | ||
return; | ||
os_release(voucher); | ||
} | ||
|
||
#else // __APPLE__ | ||
|
||
// Declare some do-nothing stubs for OSes without voucher support. | ||
typedef void *voucher_t; | ||
static inline voucher_t _Nullable voucher_copy(void) { return nullptr; } | ||
static inline voucher_t _Nullable voucher_adopt(voucher_t _Nullable voucher) { | ||
return nullptr; | ||
} | ||
static inline bool voucher_needs_adopt(voucher_t _Nullable voucher) { | ||
return true; | ||
} | ||
static inline void swift_voucher_release(voucher_t _Nullable voucher) {} | ||
#endif // __APPLE__ | ||
|
||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.