"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "stdlib/toolchain/Compatibility56/include/Concurrency/VoucherSupport.h" between
swift-swift-5.8-RELEASE.tar.gz and swift-swift-5.8.1-RELEASE.tar.gz

About: Swift is a general-purpose programming language built using a modern approach to safety, performance, and software design patterns (developed by Apple).

VoucherSupport.h  (swift-swift-5.8-RELEASE):VoucherSupport.h  (swift-swift-5.8.1-RELEASE)
skipping to change at line 34 skipping to change at line 34
namespace swift { namespace swift {
/// A class which manages voucher adoption for Job and Task objects. /// A class which manages voucher adoption for Job and Task objects.
class VoucherManager { class VoucherManager {
/// The original voucher that was set on the thread before Swift started /// The original voucher that was set on the thread before Swift started
/// doing async work. This must be restored on the thread after we finish /// doing async work. This must be restored on the thread after we finish
/// async work. /// async work.
llvm::Optional<voucher_t> OriginalVoucher; llvm::Optional<voucher_t> OriginalVoucher;
/// Determine whether vouchers are disabled entirely. This evaluates
/// true on platforms whose concurrency library does not support the
/// propagation of vouchers, in which case all of the operations of
/// this class must be no-ops.
static bool vouchersAreDisabled();
public: public:
VoucherManager() { VoucherManager() {
SWIFT_TASK_DEBUG_LOG("[%p] Constructing VoucherManager", this); SWIFT_TASK_DEBUG_LOG("[%p] Constructing VoucherManager", this);
} }
/// Clean up after completing async work, restoring the original voucher on /// Clean up after completing async work, restoring the original voucher on
/// the current thread if necessary. This MUST be called before the /// the current thread if necessary. This MUST be called before the
/// VoucherManager object is destroyed. It may also be called in other /// VoucherManager object is destroyed. It may also be called in other
/// places to restore the original voucher and reset the VoucherManager. /// places to restore the original voucher and reset the VoucherManager.
void leave() { void leave() {
if (vouchersAreDisabled())
return;
if (OriginalVoucher) { if (OriginalVoucher) {
SWIFT_TASK_DEBUG_LOG("[%p] Restoring original voucher %p", this, SWIFT_TASK_DEBUG_LOG("[%p] Restoring original voucher %p", this,
*OriginalVoucher); *OriginalVoucher);
if (swift_voucher_needs_adopt(*OriginalVoucher)) { if (swift_voucher_needs_adopt(*OriginalVoucher)) {
auto previous = voucher_adopt(*OriginalVoucher); auto previous = voucher_adopt(*OriginalVoucher);
swift_voucher_release(previous); swift_voucher_release(previous);
} else { } else {
swift_voucher_release(*OriginalVoucher); swift_voucher_release(*OriginalVoucher);
} }
OriginalVoucher = llvm::None; OriginalVoucher = llvm::None;
skipping to change at line 65 skipping to change at line 74
SWIFT_TASK_DEBUG_LOG("[%p] Leaving empty VoucherManager", this); SWIFT_TASK_DEBUG_LOG("[%p] Leaving empty VoucherManager", this);
} }
~VoucherManager() { assert(!OriginalVoucher); } ~VoucherManager() { assert(!OriginalVoucher); }
/// Set up for a new Job by adopting its voucher on the current thread. This /// Set up for a new Job by adopting its voucher on the current thread. This
/// takes over ownership of the voucher from the Job object. For plain Jobs, /// takes over ownership of the voucher from the Job object. For plain Jobs,
/// this is permanent. For Tasks, the voucher must be restored using /// this is permanent. For Tasks, the voucher must be restored using
/// restoreVoucher if the task suspends. /// restoreVoucher if the task suspends.
void swapToJob(Job *job) { void swapToJob(Job *job) {
if (vouchersAreDisabled())
return;
SWIFT_TASK_DEBUG_LOG("[%p] Swapping jobs to %p", this, job); SWIFT_TASK_DEBUG_LOG("[%p] Swapping jobs to %p", this, job);
assert(job); assert(job);
assert(job->Voucher != SWIFT_DEAD_VOUCHER); assert(job->Voucher != SWIFT_DEAD_VOUCHER);
voucher_t previous; voucher_t previous;
if (swift_voucher_needs_adopt(job->Voucher)) { if (swift_voucher_needs_adopt(job->Voucher)) {
// If we need to adopt the voucher, do so, and grab the old one. // If we need to adopt the voucher, do so, and grab the old one.
SWIFT_TASK_DEBUG_LOG("[%p] Swapping jobs to %p, adopting voucher %p", SWIFT_TASK_DEBUG_LOG("[%p] Swapping jobs to %p, adopting voucher %p",
this, job, job->Voucher); this, job, job->Voucher);
previous = voucher_adopt(job->Voucher); previous = voucher_adopt(job->Voucher);
skipping to change at line 102 skipping to change at line 114
} else { } else {
// We already have an original voucher. The one we grabbed above is not // We already have an original voucher. The one we grabbed above is not
// needed. We own it, so destroy it here. // needed. We own it, so destroy it here.
swift_voucher_release(previous); swift_voucher_release(previous);
} }
} }
// Take the current thread's adopted voucher and place it back into the task // Take the current thread's adopted voucher and place it back into the task
// that previously owned it, re-adopting the thread's original voucher. // that previously owned it, re-adopting the thread's original voucher.
void restoreVoucher(AsyncTask *task) { void restoreVoucher(AsyncTask *task) {
if (vouchersAreDisabled())
return;
SWIFT_TASK_DEBUG_LOG("[%p] Restoring %svoucher on task %p", this, SWIFT_TASK_DEBUG_LOG("[%p] Restoring %svoucher on task %p", this,
OriginalVoucher ? "" : "missing ", task); OriginalVoucher ? "" : "missing ", task);
assert(OriginalVoucher); assert(OriginalVoucher);
assert(task->Voucher == SWIFT_DEAD_VOUCHER); assert(task->Voucher == SWIFT_DEAD_VOUCHER);
if (swift_voucher_needs_adopt(*OriginalVoucher)) { if (swift_voucher_needs_adopt(*OriginalVoucher)) {
// Adopt the execution thread's original voucher. The task's voucher is // Adopt the execution thread's original voucher. The task's voucher is
// the one currently adopted, and is returned by voucher_adopt. // the one currently adopted, and is returned by voucher_adopt.
task->Voucher = voucher_adopt(*OriginalVoucher); task->Voucher = voucher_adopt(*OriginalVoucher);
} else { } else {
 End of changes. 4 change blocks. 
0 lines changed or deleted 15 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)