-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathExecutorImpl.cpp
93 lines (77 loc) · 3.21 KB
/
ExecutorImpl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//===--- ExecutorImpl.cpp - C++ side of executor impl ---------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2025 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
//
//===----------------------------------------------------------------------===//
#if SWIFT_CONCURRENCY_USES_DISPATCH
#include <dispatch/dispatch.h>
#endif
#include "Error.h"
#include "ExecutorBridge.h"
using namespace swift;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
extern "C" SWIFT_CC(swift)
void _swift_task_checkIsolatedSwift(
HeapObject *executor,
const Metadata *executorType,
const SerialExecutorWitnessTable *witnessTable
);
extern "C" SWIFT_CC(swift) bool _swift_task_isMainExecutorSwift(
HeapObject *executor, const Metadata *executorType,
const SerialExecutorWitnessTable *witnessTable);
extern "C" SWIFT_CC(swift) void swift_task_checkIsolatedImpl(
SerialExecutorRef executor) {
HeapObject *identity = executor.getIdentity();
// We might be being called with an actor rather than a "proper"
// SerialExecutor; in that case, we won't have a SerialExecutor witness
// table.
if (executor.hasSerialExecutorWitnessTable()) {
_swift_task_checkIsolatedSwift(identity, swift_getObjectType(identity),
executor.getSerialExecutorWitnessTable());
} else {
const Metadata *objectType = swift_getObjectType(executor.getIdentity());
auto typeName = swift_getTypeName(objectType, true);
swift_Concurrency_fatalError(
0, "Incorrect actor executor assumption; expected '%.*s' executor.\n",
(int)typeName.length, typeName.data);
}
}
extern "C" SWIFT_CC(swift)
bool _swift_task_isIsolatingCurrentContextSwift(
HeapObject *executor,
const Metadata *executorType,
const SerialExecutorWitnessTable *witnessTable
);
extern "C" SWIFT_CC(swift) bool swift_task_isIsolatingCurrentContextImpl(
SerialExecutorRef executor) {
HeapObject *identity = executor.getIdentity();
// We might be being called with an actor rather than a "proper"
// SerialExecutor; in that case, we won't have a SerialExecutor witness
// table.
if (executor.hasSerialExecutorWitnessTable()) {
return _swift_task_isIsolatingCurrentContextSwift(
identity, swift_getObjectType(identity),
executor.getSerialExecutorWitnessTable());
} else {
const Metadata *objectType = swift_getObjectType(executor.getIdentity());
auto typeName = swift_getTypeName(objectType, true);
swift_Concurrency_fatalError(
0, "Incorrect actor executor assumption; expected '%.*s' executor.\n",
(int)typeName.length, typeName.data);
}
}
extern "C" SWIFT_CC(swift) bool swift_task_isMainExecutorImpl(
SerialExecutorRef executor) {
HeapObject *identity = executor.getIdentity();
return executor.hasSerialExecutorWitnessTable() &&
_swift_task_isMainExecutorSwift(
identity, swift_getObjectType(identity),
executor.getSerialExecutorWitnessTable());
}