From 7cca75c8e95f129a21c33f1f4568e90e9e397f9d Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Wed, 29 Jun 2022 10:28:53 -0500 Subject: Add AppWaitForSingleObject/MultipleObjects, ThreadWaitForCompletion. --- src/libs/dutil/WixToolset.DUtil/apputil.cpp | 68 +++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'src/libs/dutil/WixToolset.DUtil/apputil.cpp') diff --git a/src/libs/dutil/WixToolset.DUtil/apputil.cpp b/src/libs/dutil/WixToolset.DUtil/apputil.cpp index 9e75082a..42f589dc 100644 --- a/src/libs/dutil/WixToolset.DUtil/apputil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/apputil.cpp @@ -313,6 +313,74 @@ LExit: return hr; } +DAPI_(HRESULT) AppWaitForSingleObject( + __in HANDLE hHandle, + __in DWORD dwMilliseconds + ) +{ + HRESULT hr = S_OK; + DWORD dwResult = 0; + + dwResult = ::WaitForSingleObject(hHandle, dwMilliseconds); + if (WAIT_TIMEOUT == dwResult) + { + ExitFunction1(hr = HRESULT_FROM_WIN32(dwResult)); + } + else if (WAIT_ABANDONED == dwResult) + { + AppExitOnWin32Error(dwResult, hr, "Abandoned wait for single object."); + } + else if (WAIT_OBJECT_0 != dwResult) + { + AssertSz(WAIT_FAILED == dwResult, "Unexpected return code from WaitForSingleObject."); + AppExitWithLastError(hr, "Failed to wait for single object."); + } + +LExit: + return hr; +} + +DAPI_(HRESULT) AppWaitForMultipleObjects( + __in DWORD dwCount, + __in const HANDLE* rghHandles, + __in BOOL fWaitAll, + __in DWORD dwMilliseconds, + __out_opt DWORD* pdwSignaledIndex + ) +{ + HRESULT hr = S_OK; + DWORD dwResult = 0; + DWORD dwSignaledIndex = dwCount; + + dwResult = ::WaitForMultipleObjects(dwCount, rghHandles, fWaitAll, dwMilliseconds); + if (WAIT_TIMEOUT == dwResult) + { + ExitFunction1(hr = HRESULT_FROM_WIN32(dwResult)); + } + else if (WAIT_ABANDONED_0 <= dwResult && (WAIT_ABANDONED_0 + dwCount) > dwResult) + { + dwSignaledIndex = dwResult - WAIT_ABANDONED_0; + AppExitOnWin32Error(dwResult, hr, "Abandoned wait for multiple objects, index: %u.", dwSignaledIndex); + } + else if (WAIT_OBJECT_0 <= dwResult && (WAIT_OBJECT_0 + dwCount) > dwResult) + { + dwSignaledIndex = dwResult - WAIT_OBJECT_0; + } + else + { + AssertSz(WAIT_FAILED == dwResult, "Unexpected return code from WaitForMultipleObjects."); + AppExitWithLastError(hr, "Failed to wait for multiple objects."); + } + +LExit: + if (pdwSignaledIndex) + { + *pdwSignaledIndex = dwSignaledIndex; + } + + return hr; +} + static HRESULT EscapeCommandLineArgument( __in_z LPCWSTR wzArgument, __out_z LPWSTR* psczEscaped -- cgit v1.2.3-55-g6feb