Skip to content

Commit

Permalink
Assertion delegate should be called on main thread
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=266981
rdar://120365684

Reviewed by Andy Estes.

* Source/WebKit/UIProcess/Cocoa/ProcessAssertionCocoa.mm:
(WebKit::ProcessAssertion::ProcessAssertion):

Canonical link: https://commits.webkit.org/272704@main
  • Loading branch information
pvollan committed Jan 5, 2024
1 parent b674f6c commit 4b07b80
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Source/WebKit/UIProcess/Cocoa/ProcessAssertionCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,20 @@ static ASCIILiteral runningBoardDomainForAssertionType(ProcessAssertionType asse
ASCIILiteral runningBoardAssertionName = runningBoardNameForAssertionType(m_assertionType);
ASCIILiteral runningBoardDomain = runningBoardDomainForAssertionType(m_assertionType);
auto didInvalidateBlock = [weakThis = ThreadSafeWeakPtr { *this }, runningBoardAssertionName] () {
auto strongThis = weakThis.get();
RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion: RBS %{public}s assertion for process with PID=%d was invalidated", strongThis.get(), runningBoardAssertionName.characters(), strongThis ? strongThis->m_pid : 0);
if (strongThis)
strongThis->processAssertionWasInvalidated();
RunLoop::main().dispatch([weakThis = WTFMove(weakThis), runningBoardAssertionName = WTFMove(runningBoardAssertionName)] {
auto strongThis = weakThis.get();
RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion: RBS %{public}s assertion for process with PID=%d was invalidated", strongThis.get(), runningBoardAssertionName.characters(), strongThis ? strongThis->m_pid : 0);
if (strongThis)
strongThis->processAssertionWasInvalidated();
});
};
auto willInvalidateBlock = [weakThis = ThreadSafeWeakPtr { *this }, runningBoardAssertionName] () {
auto strongThis = weakThis.get();
RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() RBS %{public}s assertion for process with PID=%d will be invalidated", strongThis.get(), runningBoardAssertionName.characters(), strongThis ? strongThis->m_pid : 0);
if (strongThis)
strongThis->processAssertionWillBeInvalidated();
RunLoop::main().dispatch([weakThis = WTFMove(weakThis), runningBoardAssertionName = WTFMove(runningBoardAssertionName)] {
auto strongThis = weakThis.get();
RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() RBS %{public}s assertion for process with PID=%d will be invalidated", strongThis.get(), runningBoardAssertionName.characters(), strongThis ? strongThis->m_pid : 0);
if (strongThis)
strongThis->processAssertionWillBeInvalidated();
});
};
AssertionCapability capability { process.environmentIdentifier(), runningBoardDomain, runningBoardAssertionName, WTFMove(willInvalidateBlock), WTFMove(didInvalidateBlock) };
m_capability = capability.platformCapability();
Expand Down

0 comments on commit 4b07b80

Please sign in to comment.