Skip to content

Commit 32e02fa

Browse files
authored
Merge pull request #41362 from apple/rokhinip/86100521-actor-runtime-escalation
Priority inversion avoidance in Actor Runtime
2 parents b0a038b + a3e3c3f commit 32e02fa

File tree

5 files changed

+863
-705
lines changed

5 files changed

+863
-705
lines changed

include/swift/Reflection/ReflectionContext.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,21 +1504,25 @@ class ReflectionContext
15041504

15051505
std::pair<llvm::Optional<std::string>, ActorInfo>
15061506
actorInfo(StoredPointer ActorPtr) {
1507-
using DefaultActorImpl = DefaultActorImpl<Runtime>;
1507+
if (supportsPriorityEscalation) {
1508+
return {std::string("Failure reading actor with escalation support"), {}};
1509+
}
1510+
1511+
using DefaultActorImpl = DefaultActorImpl<Runtime, ActiveActorStatusWithoutEscalation<Runtime>>;
15081512

15091513
auto ActorObj = readObj<DefaultActorImpl>(ActorPtr);
15101514
if (!ActorObj)
15111515
return {std::string("failure reading actor"), {}};
15121516

15131517
ActorInfo Info{};
1514-
Info.Flags = ActorObj->Flags;
1518+
Info.Flags = ActorObj->Status.Flags[0];
15151519

15161520
// Status is the low 3 bits of Flags. Status of 0 is Idle. Don't read
15171521
// FirstJob when idle.
15181522
auto Status = Info.Flags & 0x7;
15191523
if (Status != 0) {
15201524
// This is a JobRef which stores flags in the low bits.
1521-
Info.FirstJob = ActorObj->FirstJob & ~StoredPointer(0x3);
1525+
Info.FirstJob = ActorObj->Status.FirstJob & ~StoredPointer(0x3);
15221526
}
15231527
return {llvm::None, Info};
15241528
}

include/swift/Reflection/RuntimeInternals.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ struct StackAllocator {
9696
template <typename Runtime>
9797
struct ActiveTaskStatusWithEscalation {
9898
uint32_t Flags;
99-
uint32_t DrainLock[(sizeof(typename Runtime::StoredPointer) == 8) ? 1 : 2];
99+
uint32_t ExecutionLock[(sizeof(typename Runtime::StoredPointer) == 8) ? 1 : 2];
100100
typename Runtime::StoredPointer Record;
101101
};
102102

@@ -150,10 +150,22 @@ struct FutureAsyncContextPrefix {
150150
};
151151

152152
template <typename Runtime>
153+
struct ActiveActorStatusWithEscalation {
154+
uint32_t Flags;
155+
uint32_t DrainLock[(sizeof(typename Runtime::StoredPointer) == 8) ? 1 : 2];
156+
typename Runtime::StoredPointer FirstJob;
157+
};
158+
159+
template <typename Runtime>
160+
struct ActiveActorStatusWithoutEscalation {
161+
uint32_t Flags[sizeof(typename Runtime::StoredPointer) == 8 ? 2 : 1];
162+
typename Runtime::StoredPointer FirstJob;
163+
};
164+
165+
template <typename Runtime, typename ActiveActorStatus>
153166
struct DefaultActorImpl {
154167
HeapObject<Runtime> HeapObject;
155-
typename Runtime::StoredPointer FirstJob;
156-
typename Runtime::StoredSize Flags;
168+
ActiveActorStatus Status;
157169
};
158170

159171
template <typename Runtime>

0 commit comments

Comments
 (0)