Skip to content

Commit

Permalink
Remove cancel optimization for packageQuery caller (#1472)
Browse files Browse the repository at this point in the history
  • Loading branch information
sreadingMSFT authored Sep 16, 2021
1 parent 2a9d1c6 commit 7fb08ff
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/Microsoft.Management.Deployment/PackageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ namespace winrt::Microsoft::Management::Deployment::implementation
}

wil::unique_event progressEvent{ wil::EventOptions::None };
wil::unique_event cancelWaitEvent{ wil::EventOptions::None };

std::atomic<winrt::Microsoft::Management::Deployment::InstallProgress> installProgress;
queueItem->GetContext().AddProgressCallbackFunction([&installProgress, &progressEvent](
Expand All @@ -448,7 +447,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
);

std::weak_ptr<Execution::OrchestratorQueueItem> weakQueueItem(queueItem);
cancellationToken.callback([weakQueueItem, &canCancelQueueItem, &cancelWaitEvent]
cancellationToken.callback([weakQueueItem, &canCancelQueueItem]
{
if (canCancelQueueItem)
{
Expand All @@ -458,21 +457,15 @@ namespace winrt::Microsoft::Management::Deployment::implementation
Execution::ContextOrchestrator::Instance().CancelQueueItem(*strongQueueItem);
}
}
else
{
cancelWaitEvent.SetEvent();
}
});

// Wait for completion or progress events.
// Waiting for both on the same thread ensures that progress is never reported after the async operation itself has completed.
bool completionEventFired = false;
bool cancelWaitEventFired = false;
HANDLE operationEvents[3];
HANDLE operationEvents[2];
operationEvents[0] = progressEvent.get();
operationEvents[1] = queueItem->GetCompletedEvent().get();
operationEvents[2] = cancelWaitEvent.get();
while (!completionEventFired && !cancelWaitEventFired)
while (!completionEventFired)
{
DWORD dwEvent = WaitForMultipleObjects(
_countof(operationEvents) /* number of events */,
Expand All @@ -497,11 +490,6 @@ namespace winrt::Microsoft::Management::Deployment::implementation
completionEventFired = true;
break;

// operationEvents[2] was signaled, operation is cancelled
case WAIT_OBJECT_0 + 2:
cancelWaitEventFired = true;
break;

// Return value is invalid.
default:
THROW_LAST_ERROR();
Expand Down

0 comments on commit 7fb08ff

Please sign in to comment.