Metal: Prevent data race on mLastSubmittedCommands

There was a data-race between getting and using the pointer to
mLastSubmittedCommands in WaitForCommandsToBeScheduled and setting it
inside the scheduling handler.

Lock the mutex before calling waitUntilScheduled so that the object
doesn't get destroyed from underneath us.

Bug: chromium:1142024
Change-Id: Iadbf473530342de6d108d39285d723815452ac7c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/31260
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez 2020-11-23 16:16:00 +00:00 committed by Commit Bot service account
parent 546a7c98c8
commit 3cd31e647c
1 changed files with 10 additions and 1 deletions

View File

@ -357,7 +357,16 @@ namespace dawn_native { namespace metal {
void Device::WaitForCommandsToBeScheduled() {
SubmitPendingCommandBuffer();
[*mLastSubmittedCommands waitUntilScheduled];
// Only lock the object while we take a reference to it, otherwise we could block further
// progress if the driver calls the scheduled handler (which also acquires the lock) before
// finishing the waitUntilScheduled.
NSPRef<id<MTLCommandBuffer>> lastSubmittedCommands;
{
std::lock_guard<std::mutex> lock(mLastSubmittedCommandsMutex);
lastSubmittedCommands = mLastSubmittedCommands;
}
[*lastSubmittedCommands waitUntilScheduled];
}
MaybeError Device::WaitForIdleForDestruction() {