aboutsummaryrefslogtreecommitdiff
path: root/src/burn/engine/core.cpp
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2021-05-02 17:49:18 -0500
committerSean Hall <r.sean.hall@gmail.com>2021-05-11 19:11:19 -0500
commit8b8029f15e6e3de2fcf855037fe75dbb765475dc (patch)
treee48ee1df07f278a7a0414e9bb41d4880a126a9cd /src/burn/engine/core.cpp
parent4e2054b3ee31b2b9fae3269d76e08817a36fb51f (diff)
downloadwix-8b8029f15e6e3de2fcf855037fe75dbb765475dc.tar.gz
wix-8b8029f15e6e3de2fcf855037fe75dbb765475dc.tar.bz2
wix-8b8029f15e6e3de2fcf855037fe75dbb765475dc.zip
Synchronize access to cOverallProgressTicks between Cache and Execute.
#4414
Diffstat (limited to 'src/burn/engine/core.cpp')
-rw-r--r--src/burn/engine/core.cpp43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/burn/engine/core.cpp b/src/burn/engine/core.cpp
index 535043af..02cab7e6 100644
--- a/src/burn/engine/core.cpp
+++ b/src/burn/engine/core.cpp
@@ -8,8 +8,7 @@
8struct BURN_CACHE_THREAD_CONTEXT 8struct BURN_CACHE_THREAD_CONTEXT
9{ 9{
10 BURN_ENGINE_STATE* pEngineState; 10 BURN_ENGINE_STATE* pEngineState;
11 DWORD* pcOverallProgressTicks; 11 BURN_APPLY_CONTEXT* pApplyContext;
12 BOOL* pfRollback;
13}; 12};
14 13
15 14
@@ -606,14 +605,13 @@ extern "C" HRESULT CoreApply(
606{ 605{
607 HRESULT hr = S_OK; 606 HRESULT hr = S_OK;
608 HANDLE hLock = NULL; 607 HANDLE hLock = NULL;
609 DWORD cOverallProgressTicks = 0;
610 HANDLE hCacheThread = NULL;
611 BOOL fApplyInitialize = FALSE; 608 BOOL fApplyInitialize = FALSE;
612 BOOL fElevated = FALSE; 609 BOOL fElevated = FALSE;
613 BOOL fRegistered = FALSE; 610 BOOL fRegistered = FALSE;
614 BOOL fRollback = FALSE;
615 BOOL fSuspend = FALSE; 611 BOOL fSuspend = FALSE;
616 BOOTSTRAPPER_APPLY_RESTART restart = BOOTSTRAPPER_APPLY_RESTART_NONE; 612 BOOTSTRAPPER_APPLY_RESTART restart = BOOTSTRAPPER_APPLY_RESTART_NONE;
613 BURN_APPLY_CONTEXT applyContext = { };
614 BOOL fDeleteApplyCs = FALSE;
617 BURN_CACHE_THREAD_CONTEXT cacheThreadContext = { }; 615 BURN_CACHE_THREAD_CONTEXT cacheThreadContext = { };
618 DWORD dwPhaseCount = 0; 616 DWORD dwPhaseCount = 0;
619 BOOTSTRAPPER_APPLYCOMPLETE_ACTION applyCompleteAction = BOOTSTRAPPER_APPLYCOMPLETE_ACTION_NONE; 617 BOOTSTRAPPER_APPLYCOMPLETE_ACTION applyCompleteAction = BOOTSTRAPPER_APPLYCOMPLETE_ACTION_NONE;
@@ -675,6 +673,9 @@ extern "C" HRESULT CoreApply(
675 ExitFunction(); 673 ExitFunction();
676 } 674 }
677 675
676 fDeleteApplyCs = TRUE;
677 ::InitializeCriticalSection(&applyContext.csApply);
678
678 // Ensure the engine is cached to the working path. 679 // Ensure the engine is cached to the working path.
679 if (!pEngineState->sczBundleEngineWorkingPath) 680 if (!pEngineState->sczBundleEngineWorkingPath)
680 { 681 {
@@ -707,33 +708,32 @@ extern "C" HRESULT CoreApply(
707 { 708 {
708 // Launch the cache thread. 709 // Launch the cache thread.
709 cacheThreadContext.pEngineState = pEngineState; 710 cacheThreadContext.pEngineState = pEngineState;
710 cacheThreadContext.pcOverallProgressTicks = &cOverallProgressTicks; 711 cacheThreadContext.pApplyContext = &applyContext;
711 cacheThreadContext.pfRollback = &fRollback;
712 712
713 hCacheThread = ::CreateThread(NULL, 0, CacheThreadProc, &cacheThreadContext, 0, NULL); 713 applyContext.hCacheThread = ::CreateThread(NULL, 0, CacheThreadProc, &cacheThreadContext, 0, NULL);
714 ExitOnNullWithLastError(hCacheThread, hr, "Failed to create cache thread."); 714 ExitOnNullWithLastError(applyContext.hCacheThread, hr, "Failed to create cache thread.");
715 715
716 // If we're not caching in parallel, wait for the cache thread to terminate. 716 // If we're not caching in parallel, wait for the cache thread to terminate.
717 if (!pEngineState->fParallelCacheAndExecute) 717 if (!pEngineState->fParallelCacheAndExecute)
718 { 718 {
719 hr = WaitForCacheThread(hCacheThread); 719 hr = WaitForCacheThread(applyContext.hCacheThread);
720 ExitOnFailure(hr, "Failed while caching, aborting execution."); 720 ExitOnFailure(hr, "Failed while caching, aborting execution.");
721 721
722 ReleaseHandle(hCacheThread); 722 ReleaseHandle(applyContext.hCacheThread);
723 } 723 }
724 } 724 }
725 725
726 // Execute. 726 // Execute.
727 if (pEngineState->plan.cExecuteActions) 727 if (pEngineState->plan.cExecuteActions)
728 { 728 {
729 hr = ApplyExecute(pEngineState, hCacheThread, &cOverallProgressTicks, &fRollback, &fSuspend, &restart); 729 hr = ApplyExecute(pEngineState, &applyContext, &fSuspend, &restart);
730 UserExperienceExecutePhaseComplete(&pEngineState->userExperience, hr); // signal that execute completed. 730 UserExperienceExecutePhaseComplete(&pEngineState->userExperience, hr); // signal that execute completed.
731 } 731 }
732 732
733 // Wait for cache thread to terminate, this should return immediately unless we're waiting for layout to complete. 733 // Wait for cache thread to terminate, this should return immediately unless we're waiting for layout to complete.
734 if (hCacheThread) 734 if (applyContext.hCacheThread)
735 { 735 {
736 HRESULT hrCached = WaitForCacheThread(hCacheThread); 736 HRESULT hrCached = WaitForCacheThread(applyContext.hCacheThread);
737 if (SUCCEEDED(hr)) 737 if (SUCCEEDED(hr))
738 { 738 {
739 hr = hrCached; 739 hr = hrCached;
@@ -741,7 +741,7 @@ extern "C" HRESULT CoreApply(
741 } 741 }
742 742
743 // If something went wrong or force restarted, skip cleaning. 743 // If something went wrong or force restarted, skip cleaning.
744 if (FAILED(hr) || fRollback || fSuspend || BOOTSTRAPPER_APPLY_RESTART_INITIATED == restart) 744 if (FAILED(hr) || applyContext.fRollback || fSuspend || BOOTSTRAPPER_APPLY_RESTART_INITIATED == restart)
745 { 745 {
746 ExitFunction(); 746 ExitFunction();
747 } 747 }
@@ -756,7 +756,7 @@ LExit:
756 // Unregister. 756 // Unregister.
757 if (fRegistered) 757 if (fRegistered)
758 { 758 {
759 ApplyUnregister(pEngineState, FAILED(hr) || fRollback, fSuspend, restart); 759 ApplyUnregister(pEngineState, FAILED(hr) || applyContext.fRollback, fSuspend, restart);
760 } 760 }
761 761
762 if (fElevated) 762 if (fElevated)
@@ -777,7 +777,12 @@ LExit:
777 ::CloseHandle(hLock); 777 ::CloseHandle(hLock);
778 } 778 }
779 779
780 ReleaseHandle(hCacheThread); 780 ReleaseHandle(applyContext.hCacheThread);
781
782 if (fDeleteApplyCs)
783 {
784 DeleteCriticalSection(&applyContext.csApply);
785 }
781 786
782 UserExperienceOnApplyComplete(&pEngineState->userExperience, hr, restart, &applyCompleteAction); 787 UserExperienceOnApplyComplete(&pEngineState->userExperience, hr, restart, &applyCompleteAction);
783 if (BOOTSTRAPPER_APPLYCOMPLETE_ACTION_RESTART == applyCompleteAction) 788 if (BOOTSTRAPPER_APPLYCOMPLETE_ACTION_RESTART == applyCompleteAction)
@@ -1712,8 +1717,6 @@ static DWORD WINAPI CacheThreadProc(
1712 HRESULT hr = S_OK; 1717 HRESULT hr = S_OK;
1713 BURN_CACHE_THREAD_CONTEXT* pContext = reinterpret_cast<BURN_CACHE_THREAD_CONTEXT*>(lpThreadParameter); 1718 BURN_CACHE_THREAD_CONTEXT* pContext = reinterpret_cast<BURN_CACHE_THREAD_CONTEXT*>(lpThreadParameter);
1714 BURN_ENGINE_STATE* pEngineState = pContext->pEngineState; 1719 BURN_ENGINE_STATE* pEngineState = pContext->pEngineState;
1715 DWORD* pcOverallProgressTicks = pContext->pcOverallProgressTicks;
1716 BOOL* pfRollback = pContext->pfRollback;
1717 BOOL fComInitialized = FALSE; 1720 BOOL fComInitialized = FALSE;
1718 1721
1719 // initialize COM 1722 // initialize COM
@@ -1722,7 +1725,7 @@ static DWORD WINAPI CacheThreadProc(
1722 fComInitialized = TRUE; 1725 fComInitialized = TRUE;
1723 1726
1724 // cache packages 1727 // cache packages
1725 hr = ApplyCache(pEngineState->section.hSourceEngineFile, &pEngineState->userExperience, &pEngineState->variables, &pEngineState->plan, pEngineState->companionConnection.hCachePipe, pcOverallProgressTicks, pfRollback); 1728 hr = ApplyCache(pEngineState->section.hSourceEngineFile, &pEngineState->userExperience, &pEngineState->variables, &pEngineState->plan, pEngineState->companionConnection.hCachePipe, pContext->pApplyContext);
1726 1729
1727LExit: 1730LExit:
1728 UserExperienceExecutePhaseComplete(&pEngineState->userExperience, hr); // signal that cache completed. 1731 UserExperienceExecutePhaseComplete(&pEngineState->userExperience, hr); // signal that cache completed.