From 98080672cdbbde00ea40a96c1ce38e8a52f24fee Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Wed, 19 Oct 2022 15:44:40 -0500 Subject: Add queutil so Burn can manage its own queue of BA requested actions. Fixes 6349 --- src/libs/dutil/WixToolset.DUtil/dutil.vcxproj | 2 + .../dutil/WixToolset.DUtil/dutil.vcxproj.filters | 6 + src/libs/dutil/WixToolset.DUtil/inc/dutilsources.h | 1 + src/libs/dutil/WixToolset.DUtil/inc/queutil.h | 52 ++++++++ src/libs/dutil/WixToolset.DUtil/precomp.h | 1 + src/libs/dutil/WixToolset.DUtil/queutil.cpp | 144 +++++++++++++++++++++ 6 files changed, 206 insertions(+) create mode 100644 src/libs/dutil/WixToolset.DUtil/inc/queutil.h create mode 100644 src/libs/dutil/WixToolset.DUtil/queutil.cpp (limited to 'src/libs') diff --git a/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj b/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj index c84b98fe..dc6b913f 100644 --- a/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj +++ b/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj @@ -91,6 +91,7 @@ + @@ -153,6 +154,7 @@ + diff --git a/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj.filters b/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj.filters index efadef6f..c1095651 100644 --- a/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj.filters +++ b/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj.filters @@ -135,6 +135,9 @@ Source Files + + Source Files + Source Files @@ -314,6 +317,9 @@ Header Files + + Header Files + Header Files diff --git a/src/libs/dutil/WixToolset.DUtil/inc/dutilsources.h b/src/libs/dutil/WixToolset.DUtil/inc/dutilsources.h index 664c21e5..cf10f910 100644 --- a/src/libs/dutil/WixToolset.DUtil/inc/dutilsources.h +++ b/src/libs/dutil/WixToolset.DUtil/inc/dutilsources.h @@ -64,6 +64,7 @@ typedef enum DUTIL_SOURCE DUTIL_SOURCE_WNDUTIL, DUTIL_SOURCE_ENVUTIL, DUTIL_SOURCE_THRDUTIL, + DUTIL_SOURCE_QUEUTIL, DUTIL_SOURCE_EXTERNAL = 256, } DUTIL_SOURCE; diff --git a/src/libs/dutil/WixToolset.DUtil/inc/queutil.h b/src/libs/dutil/WixToolset.DUtil/inc/queutil.h new file mode 100644 index 00000000..3b88825e --- /dev/null +++ b/src/libs/dutil/WixToolset.DUtil/inc/queutil.h @@ -0,0 +1,52 @@ +#pragma once +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + + +#ifdef __cplusplus +extern "C" { +#endif + +#define ReleaseQueue(qh, pfn, pv) if (qh) { QueDestroy(qh, pfn, pv); } +#define ReleaseNullQue(qh, pfv, pv) if (qh) { QueDestroy(qh, pfn, pv); qh = NULL; } + +typedef void* QUEUTIL_QUEUE_HANDLE; + +typedef void(CALLBACK* PFNQUEUTIL_QUEUE_RELEASE_VALUE)( + __in void* pvValue, + __in void* pvContext + ); + +extern const int QUEUTIL_QUEUE_HANDLE_BYTES; + +/******************************************************************** +QueCreate - Creates a simple queue. It is not thread safe. + +********************************************************************/ +HRESULT DAPI QueCreate( + __out_bcount(QUEUTIL_QUEUE_HANDLE_BYTES) QUEUTIL_QUEUE_HANDLE* phQueue + ); + +HRESULT DAPI QueEnqueue( + __in_bcount(QUEUTIL_QUEUE_HANDLE_BYTES) QUEUTIL_QUEUE_HANDLE hQueue, + __in void* pvValue + ); + +/******************************************************************** +QueDequeue - Returns the value from the beginning of the queue, + or E_NOMOREITEMS if the queue is empty. + +********************************************************************/ +HRESULT DAPI QueDequeue( + __in_bcount(QUEUTIL_QUEUE_HANDLE_BYTES) QUEUTIL_QUEUE_HANDLE hQueue, + __out void** ppvValue + ); + +void DAPI QueDestroy( + __in_bcount(QUEUTIL_QUEUE_HANDLE_BYTES) QUEUTIL_QUEUE_HANDLE hQueue, + __in_opt PFNQUEUTIL_QUEUE_RELEASE_VALUE pfnReleaseValue, + __in_opt void* pvContext + ); + +#ifdef __cplusplus +} +#endif diff --git a/src/libs/dutil/WixToolset.DUtil/precomp.h b/src/libs/dutil/WixToolset.DUtil/precomp.h index b628d271..607f7ce6 100644 --- a/src/libs/dutil/WixToolset.DUtil/precomp.h +++ b/src/libs/dutil/WixToolset.DUtil/precomp.h @@ -75,6 +75,7 @@ #include "perfutil.h" #include "polcutil.h" #include "procutil.h" +#include "queutil.h" #include "regutil.h" #include "butil.h" // NOTE: Butil must come after Regutil. #include "resrutil.h" diff --git a/src/libs/dutil/WixToolset.DUtil/queutil.cpp b/src/libs/dutil/WixToolset.DUtil/queutil.cpp new file mode 100644 index 00000000..c5d2d736 --- /dev/null +++ b/src/libs/dutil/WixToolset.DUtil/queutil.cpp @@ -0,0 +1,144 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +#include "precomp.h" + + +// Exit macros +#define QueExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_QUEUTIL, x, s, __VA_ARGS__) +#define QueExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_QUEUTIL, x, s, __VA_ARGS__) +#define QueExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_QUEUTIL, x, s, __VA_ARGS__) +#define QueExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_QUEUTIL, x, s, __VA_ARGS__) +#define QueExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_QUEUTIL, x, s, __VA_ARGS__) +#define QueExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_QUEUTIL, x, s, __VA_ARGS__) +#define QueExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_QUEUTIL, p, x, e, s, __VA_ARGS__) +#define QueExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_QUEUTIL, p, x, s, __VA_ARGS__) +#define QueExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_QUEUTIL, p, x, e, s, __VA_ARGS__) +#define QueExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_QUEUTIL, p, x, s, __VA_ARGS__) +#define QueExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_QUEUTIL, e, x, s, __VA_ARGS__) +#define QueExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_QUEUTIL, g, x, s, __VA_ARGS__) + + +struct QUEUTIL_QUEUE_ITEM +{ + QUEUTIL_QUEUE_ITEM* pNext; + void* pvValue; +}; + +struct QUEUTIL_QUEUE_STRUCT +{ + QUEUTIL_QUEUE_ITEM* pFirst; + QUEUTIL_QUEUE_ITEM* pLast; +}; + +const int QUEUTIL_QUEUE_HANDLE_BYTES = sizeof(QUEUTIL_QUEUE_STRUCT); + +extern "C" HRESULT DAPI QueCreate( + __out_bcount(QUEUTIL_QUEUE_HANDLE_BYTES) QUEUTIL_QUEUE_HANDLE* phQueue + ) +{ + HRESULT hr = S_OK; + + QueExitOnNull(phQueue, hr, E_INVALIDARG, "Handle not specified while creating queue."); + + *phQueue = reinterpret_cast(MemAlloc(QUEUTIL_QUEUE_HANDLE_BYTES, TRUE)); + QueExitOnNull(*phQueue, hr, E_OUTOFMEMORY, "Failed to allocate queue object."); + +LExit: + return hr; +} + +extern "C" HRESULT DAPI QueEnqueue( + __in_bcount(QUEUTIL_QUEUE_HANDLE_BYTES) QUEUTIL_QUEUE_HANDLE hQueue, + __in void* pvValue + ) +{ + HRESULT hr = S_OK; + QUEUTIL_QUEUE_ITEM* pItem = NULL; + QUEUTIL_QUEUE_STRUCT* pQueue = reinterpret_cast(hQueue); + + QueExitOnNull(pQueue, hr, E_INVALIDARG, "Handle not specified while enqueing value."); + + pItem = reinterpret_cast(MemAlloc(sizeof(QUEUTIL_QUEUE_ITEM), TRUE)); + QueExitOnNull(pItem, hr, E_OUTOFMEMORY, "Failed to allocate queue item."); + + pItem->pvValue = pvValue; + + if (!pQueue->pLast) + { + pQueue->pFirst = pItem; + } + else + { + pQueue->pLast->pNext = pItem; + } + + pQueue->pLast = pItem; + + pItem = NULL; + +LExit: + ReleaseMem(pItem); + + return hr; +} + +extern "C" HRESULT DAPI QueDequeue( + __in_bcount(QUEUTIL_QUEUE_HANDLE_BYTES) QUEUTIL_QUEUE_HANDLE hQueue, + __out void** ppvValue + ) +{ + HRESULT hr = S_OK; + QUEUTIL_QUEUE_ITEM* pItem = NULL; + QUEUTIL_QUEUE_STRUCT* pQueue = reinterpret_cast(hQueue); + + QueExitOnNull(pQueue, hr, E_INVALIDARG, "Handle not specified while dequeing value."); + + if (!pQueue->pFirst) + { + *ppvValue = NULL; + ExitFunction1(hr = E_NOMOREITEMS); + } + + pItem = pQueue->pFirst; + + if (!pItem->pNext) + { + pQueue->pFirst = NULL; + pQueue->pLast = NULL; + } + else + { + pQueue->pFirst = pItem->pNext; + } + + *ppvValue = pItem->pvValue; + +LExit: + ReleaseMem(pItem); + + return hr; +} + +extern "C" void DAPI QueDestroy( + __in_bcount(QUEUTIL_QUEUE_HANDLE_BYTES) QUEUTIL_QUEUE_HANDLE hQueue, + __in_opt PFNQUEUTIL_QUEUE_RELEASE_VALUE pfnReleaseValue, + __in_opt void* pvContext + ) +{ + HRESULT hr = S_OK; + void* pvValue = NULL; + + hr = hQueue ? QueDequeue(hQueue, &pvValue) : E_NOMOREITEMS; + + while (SUCCEEDED(hr)) + { + if (pfnReleaseValue) + { + pfnReleaseValue(pvValue, pvContext); + } + + hr = QueDequeue(hQueue, &pvValue); + } + + ReleaseMem(hQueue); +} -- cgit v1.2.3-55-g6feb