diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2022-10-19 15:44:40 -0500 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2022-10-25 15:13:06 -0500 |
| commit | 98080672cdbbde00ea40a96c1ce38e8a52f24fee (patch) | |
| tree | 9c0b859f147d55d5c4caadccfd764ca84ed7e648 /src/libs/dutil/WixToolset.DUtil/queutil.cpp | |
| parent | 28e9c7c14d2a156b55476f6b8e39e13f17aa87b6 (diff) | |
| download | wix-98080672cdbbde00ea40a96c1ce38e8a52f24fee.tar.gz wix-98080672cdbbde00ea40a96c1ce38e8a52f24fee.tar.bz2 wix-98080672cdbbde00ea40a96c1ce38e8a52f24fee.zip | |
Add queutil so Burn can manage its own queue of BA requested actions.
Fixes 6349
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/queutil.cpp')
| -rw-r--r-- | src/libs/dutil/WixToolset.DUtil/queutil.cpp | 144 |
1 files changed, 144 insertions, 0 deletions
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 @@ | |||
| 1 | // 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. | ||
| 2 | |||
| 3 | #include "precomp.h" | ||
| 4 | |||
| 5 | |||
| 6 | // Exit macros | ||
| 7 | #define QueExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_QUEUTIL, x, s, __VA_ARGS__) | ||
| 8 | #define QueExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_QUEUTIL, x, s, __VA_ARGS__) | ||
| 9 | #define QueExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_QUEUTIL, x, s, __VA_ARGS__) | ||
| 10 | #define QueExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_QUEUTIL, x, s, __VA_ARGS__) | ||
| 11 | #define QueExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_QUEUTIL, x, s, __VA_ARGS__) | ||
| 12 | #define QueExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_QUEUTIL, x, s, __VA_ARGS__) | ||
| 13 | #define QueExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_QUEUTIL, p, x, e, s, __VA_ARGS__) | ||
| 14 | #define QueExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_QUEUTIL, p, x, s, __VA_ARGS__) | ||
| 15 | #define QueExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_QUEUTIL, p, x, e, s, __VA_ARGS__) | ||
| 16 | #define QueExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_QUEUTIL, p, x, s, __VA_ARGS__) | ||
| 17 | #define QueExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_QUEUTIL, e, x, s, __VA_ARGS__) | ||
| 18 | #define QueExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_QUEUTIL, g, x, s, __VA_ARGS__) | ||
| 19 | |||
| 20 | |||
| 21 | struct QUEUTIL_QUEUE_ITEM | ||
| 22 | { | ||
| 23 | QUEUTIL_QUEUE_ITEM* pNext; | ||
| 24 | void* pvValue; | ||
| 25 | }; | ||
| 26 | |||
| 27 | struct QUEUTIL_QUEUE_STRUCT | ||
| 28 | { | ||
| 29 | QUEUTIL_QUEUE_ITEM* pFirst; | ||
| 30 | QUEUTIL_QUEUE_ITEM* pLast; | ||
| 31 | }; | ||
| 32 | |||
| 33 | const int QUEUTIL_QUEUE_HANDLE_BYTES = sizeof(QUEUTIL_QUEUE_STRUCT); | ||
| 34 | |||
| 35 | extern "C" HRESULT DAPI QueCreate( | ||
| 36 | __out_bcount(QUEUTIL_QUEUE_HANDLE_BYTES) QUEUTIL_QUEUE_HANDLE* phQueue | ||
| 37 | ) | ||
| 38 | { | ||
| 39 | HRESULT hr = S_OK; | ||
| 40 | |||
| 41 | QueExitOnNull(phQueue, hr, E_INVALIDARG, "Handle not specified while creating queue."); | ||
| 42 | |||
| 43 | *phQueue = reinterpret_cast<QUEUTIL_QUEUE_HANDLE>(MemAlloc(QUEUTIL_QUEUE_HANDLE_BYTES, TRUE)); | ||
| 44 | QueExitOnNull(*phQueue, hr, E_OUTOFMEMORY, "Failed to allocate queue object."); | ||
| 45 | |||
| 46 | LExit: | ||
| 47 | return hr; | ||
| 48 | } | ||
| 49 | |||
| 50 | extern "C" HRESULT DAPI QueEnqueue( | ||
| 51 | __in_bcount(QUEUTIL_QUEUE_HANDLE_BYTES) QUEUTIL_QUEUE_HANDLE hQueue, | ||
| 52 | __in void* pvValue | ||
| 53 | ) | ||
| 54 | { | ||
| 55 | HRESULT hr = S_OK; | ||
| 56 | QUEUTIL_QUEUE_ITEM* pItem = NULL; | ||
| 57 | QUEUTIL_QUEUE_STRUCT* pQueue = reinterpret_cast<QUEUTIL_QUEUE_STRUCT*>(hQueue); | ||
| 58 | |||
| 59 | QueExitOnNull(pQueue, hr, E_INVALIDARG, "Handle not specified while enqueing value."); | ||
| 60 | |||
| 61 | pItem = reinterpret_cast<QUEUTIL_QUEUE_ITEM*>(MemAlloc(sizeof(QUEUTIL_QUEUE_ITEM), TRUE)); | ||
| 62 | QueExitOnNull(pItem, hr, E_OUTOFMEMORY, "Failed to allocate queue item."); | ||
| 63 | |||
| 64 | pItem->pvValue = pvValue; | ||
| 65 | |||
| 66 | if (!pQueue->pLast) | ||
| 67 | { | ||
| 68 | pQueue->pFirst = pItem; | ||
| 69 | } | ||
| 70 | else | ||
| 71 | { | ||
| 72 | pQueue->pLast->pNext = pItem; | ||
| 73 | } | ||
| 74 | |||
| 75 | pQueue->pLast = pItem; | ||
| 76 | |||
| 77 | pItem = NULL; | ||
| 78 | |||
| 79 | LExit: | ||
| 80 | ReleaseMem(pItem); | ||
| 81 | |||
| 82 | return hr; | ||
| 83 | } | ||
| 84 | |||
| 85 | extern "C" HRESULT DAPI QueDequeue( | ||
| 86 | __in_bcount(QUEUTIL_QUEUE_HANDLE_BYTES) QUEUTIL_QUEUE_HANDLE hQueue, | ||
| 87 | __out void** ppvValue | ||
| 88 | ) | ||
| 89 | { | ||
| 90 | HRESULT hr = S_OK; | ||
| 91 | QUEUTIL_QUEUE_ITEM* pItem = NULL; | ||
| 92 | QUEUTIL_QUEUE_STRUCT* pQueue = reinterpret_cast<QUEUTIL_QUEUE_STRUCT*>(hQueue); | ||
| 93 | |||
| 94 | QueExitOnNull(pQueue, hr, E_INVALIDARG, "Handle not specified while dequeing value."); | ||
| 95 | |||
| 96 | if (!pQueue->pFirst) | ||
| 97 | { | ||
| 98 | *ppvValue = NULL; | ||
| 99 | ExitFunction1(hr = E_NOMOREITEMS); | ||
| 100 | } | ||
| 101 | |||
| 102 | pItem = pQueue->pFirst; | ||
| 103 | |||
| 104 | if (!pItem->pNext) | ||
| 105 | { | ||
| 106 | pQueue->pFirst = NULL; | ||
| 107 | pQueue->pLast = NULL; | ||
| 108 | } | ||
| 109 | else | ||
| 110 | { | ||
| 111 | pQueue->pFirst = pItem->pNext; | ||
| 112 | } | ||
| 113 | |||
| 114 | *ppvValue = pItem->pvValue; | ||
| 115 | |||
| 116 | LExit: | ||
| 117 | ReleaseMem(pItem); | ||
| 118 | |||
| 119 | return hr; | ||
| 120 | } | ||
| 121 | |||
| 122 | extern "C" void DAPI QueDestroy( | ||
| 123 | __in_bcount(QUEUTIL_QUEUE_HANDLE_BYTES) QUEUTIL_QUEUE_HANDLE hQueue, | ||
| 124 | __in_opt PFNQUEUTIL_QUEUE_RELEASE_VALUE pfnReleaseValue, | ||
| 125 | __in_opt void* pvContext | ||
| 126 | ) | ||
| 127 | { | ||
| 128 | HRESULT hr = S_OK; | ||
| 129 | void* pvValue = NULL; | ||
| 130 | |||
| 131 | hr = hQueue ? QueDequeue(hQueue, &pvValue) : E_NOMOREITEMS; | ||
| 132 | |||
| 133 | while (SUCCEEDED(hr)) | ||
| 134 | { | ||
| 135 | if (pfnReleaseValue) | ||
| 136 | { | ||
| 137 | pfnReleaseValue(pvValue, pvContext); | ||
| 138 | } | ||
| 139 | |||
| 140 | hr = QueDequeue(hQueue, &pvValue); | ||
| 141 | } | ||
| 142 | |||
| 143 | ReleaseMem(hQueue); | ||
| 144 | } | ||
